diff --git a/.github/workflows/marketplace-upload.yml b/.github/workflows/marketplace-upload.yml new file mode 100644 index 0000000..6fb0bc8 --- /dev/null +++ b/.github/workflows/marketplace-upload.yml @@ -0,0 +1,11 @@ +on: + push: + tags: + - 'v*' + +name: Upload to HumHub Marketplace + +jobs: + build: + uses: humhub/actions/.github/workflows/module-marketplace-upload.yml@main + secrets: inherit diff --git a/.github/workflows/php-test-develop.yml b/.github/workflows/php-test-develop.yml new file mode 100644 index 0000000..d01ae83 --- /dev/null +++ b/.github/workflows/php-test-develop.yml @@ -0,0 +1,12 @@ +name: PHP Codeception Tests - develop + +on: + push: + schedule: + - cron: "0 0 * * 0" + +jobs: + tests: + uses: humhub/actions/.github/workflows/module-tests-develop.yml@main + with: + module-id: text-editor diff --git a/.github/workflows/php-test-master.yml b/.github/workflows/php-test-master.yml new file mode 100644 index 0000000..9d9c783 --- /dev/null +++ b/.github/workflows/php-test-master.yml @@ -0,0 +1,10 @@ +name: PHP Codeception Tests - master + +on: + push: + +jobs: + tests: + uses: humhub/actions/.github/workflows/module-tests-master.yml@main + with: + module-id: text-editor diff --git a/.github/workflows/php-test-next.yml b/.github/workflows/php-test-next.yml new file mode 100644 index 0000000..1a28b89 --- /dev/null +++ b/.github/workflows/php-test-next.yml @@ -0,0 +1,12 @@ +name: PHP Codeception Tests - next + +on: + push: + schedule: + - cron: "0 0 * * 0" + +jobs: + tests: + uses: humhub/actions/.github/workflows/module-tests-next.yml@main + with: + module-id: text-editor diff --git a/Module.php b/Module.php index 67552f5..242939b 100644 --- a/Module.php +++ b/Module.php @@ -49,7 +49,7 @@ public function canEdit(File $file): bool public function canView(File $file): bool { return $this->isSupportedType($file) && - $file->canView() && + $file->canRead() && is_readable($file->getStore()->get()); } diff --git a/tests/codeception.yml b/tests/codeception.yml new file mode 100644 index 0000000..e0193ab --- /dev/null +++ b/tests/codeception.yml @@ -0,0 +1,23 @@ +actor: Tester +namespace: text_editor +bootstrap: _bootstrap.php +settings: + suite_class: \PHPUnit_Framework_TestSuite + colors: true + shuffle: false + memory_limit: 1024M + log: true + + # This value controls whether PHPUnit attempts to backup global variables + # See https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.backupGlobals + backup_globals: true +paths: + tests: codeception + log: codeception/_output + data: codeception/_data + helpers: codeception/_support + envs: ../../../humhub/tests/config/env +config: + # the entry script URL (with host info) for functional and acceptance tests + # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL + test_entry_url: http://localhost:8080/index-test.php diff --git a/tests/codeception/_bootstrap.php b/tests/codeception/_bootstrap.php new file mode 100644 index 0000000..9bbfcf9 --- /dev/null +++ b/tests/codeception/_bootstrap.php @@ -0,0 +1,35 @@ + $testRoot]); +codecept_debug('Module root: ' . $testRoot); + +$humhubPath = getenv('HUMHUB_PATH'); +if ($humhubPath === false) { + // If no environment path was set, we assume residing in default the modules directory + $moduleConfig = require $testRoot . '/config/test.php'; + if (isset($moduleConfig['humhub_root'])) { + $humhubPath = $moduleConfig['humhub_root']; + } else { + $humhubPath = dirname(__DIR__, 5); + } +} + +\Codeception\Configuration::append(['humhub_root' => $humhubPath]); +codecept_debug('HumHub Root: ' . $humhubPath); + +// Load test configuration (/config/test.php or /config/env//test.php +$globalConfig = require $humhubPath . '/protected/humhub/tests/codeception/_loadConfig.php'; + +// Load default test bootstrap (initialize Yii...) +require $globalConfig['humhub_root'] . '/protected/humhub/tests/codeception/_bootstrap.php'; diff --git a/tests/codeception/_output/.gitignore b/tests/codeception/_output/.gitignore new file mode 100644 index 0000000..86d0cb2 --- /dev/null +++ b/tests/codeception/_output/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/tests/codeception/_support/AcceptanceTester.php b/tests/codeception/_support/AcceptanceTester.php new file mode 100644 index 0000000..0dc2f2e --- /dev/null +++ b/tests/codeception/_support/AcceptanceTester.php @@ -0,0 +1,28 @@ +amAdmin(); + + $I->amOnPage('/text-editor/config'); + $I->waitForText('Text editor'); + $I->click('#configform-allownewfiles'); + $I->click('Save'); + $I->seeSuccess(); + + $I->amOnSpace1(); + $I->click('#contentForm_message'); + $I->click('.contentForm_options .btn-group .dropdown-toggle'); + $I->waitForText('Create file (Text, Log, XML)'); + $I->click('Create file (Text, Log, XML)'); + $I->waitForText('Create file'); + $I->fillField('#createfile-filename', 'Test file name.tst'); + $I->click('Save'); + + $I->waitForText('Edit file: Test file name.tst'); + $I->executeJS('document.querySelectorAll("div.CodeMirror")[0].CodeMirror.setValue("Test\r\nLine 2")'); + $I->click('Save'); + $I->seeSuccess(); + $I->fillField('#contentFormBody .humhub-ui-richtext[contenteditable]', 'Post with test text file.'); + $I->click('Submit'); + + $I->waitForText('Post with test text file.', null, '.wall-entry'); + $I->see('Test file name.tst - 12 B', '.wall-entry .file-preview-content'); + $I->click('Test file name.tst'); + $I->waitForText('Open file'); + $I->click('View'); + $I->waitForText('View file: Test file name.tst'); + $I->see("Test\r\nLine 2"); + $I->click('Close'); + + $I->click('Test file name.tst'); + $I->waitForText('Open file'); + $I->click('Edit with Text editor'); + $I->waitForText('Edit file: Test file name.tst'); + $I->executeJS('document.querySelectorAll("div.CodeMirror")[0].CodeMirror.setValue("1st Line\r\nSecond Line")'); + $I->click('Save'); + $I->seeSuccess(); + $I->click('Test file name.tst'); + $I->waitForText('Open file'); + $I->click('View'); + $I->waitForText('View file: Test file name.tst'); + $I->see("1st Line\r\nSecond Line"); + } +} diff --git a/tests/codeception/acceptance/_bootstrap.php b/tests/codeception/acceptance/_bootstrap.php new file mode 100644 index 0000000..63fd3e0 --- /dev/null +++ b/tests/codeception/acceptance/_bootstrap.php @@ -0,0 +1,6 @@ +getModule('text-editor'); + + $this->assertFalse($module->canCreate()); + + $config = new ConfigForm(); + $config->allowNewFiles = true; + $config->save(); + + $this->assertTrue($module->canCreate()); + + $createFile = new CreateFile(); + $createFile->fileName = 'test.any'; + $testFile = $createFile->save(); + + $this->assertEquals('text/plain', $testFile->mime_type); + $this->assertTrue($module->isSupportedType($testFile)); + $this->assertTrue($module->canView($testFile)); + $this->assertTrue($module->canEdit($testFile)); + + $testFile->mime_type = 'image/jpeg'; + + $this->assertFalse($module->isSupportedType($testFile)); + $this->assertFalse($module->canView($testFile)); + $this->assertFalse($module->canEdit($testFile)); + } +} diff --git a/tests/codeception/unit/_bootstrap.php b/tests/codeception/unit/_bootstrap.php new file mode 100644 index 0000000..6c96bdd --- /dev/null +++ b/tests/codeception/unit/_bootstrap.php @@ -0,0 +1,6 @@ + ['text-editor'], + 'fixtures' => ['default'], +]; diff --git a/tests/config/unit.php b/tests/config/unit.php new file mode 100644 index 0000000..ae7fa3f --- /dev/null +++ b/tests/config/unit.php @@ -0,0 +1,5 @@ +