From b1e39cb75af9f9b562f86a1d90ea0ee477dc6554 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Tue, 23 Apr 2024 14:58:17 +0200 Subject: [PATCH 1/7] Add GitHub Actions --- .github/workflows/marketplace-upload.yml | 11 +++++++++++ .github/workflows/php-test-develop.yml | 12 ++++++++++++ .github/workflows/php-test-master.yml | 10 ++++++++++ .github/workflows/php-test-next.yml | 12 ++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 .github/workflows/marketplace-upload.yml create mode 100644 .github/workflows/php-test-develop.yml create mode 100644 .github/workflows/php-test-master.yml create mode 100644 .github/workflows/php-test-next.yml 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 From 0939d7148e8b6a79f0298a6968490c5ad9db6e87 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Tue, 23 Apr 2024 16:43:01 +0200 Subject: [PATCH 2/7] Add tests --- tests/codeception.yml | 23 ++++++++++++ tests/codeception/_bootstrap.php | 35 +++++++++++++++++++ tests/codeception/_output/.gitignore | 4 +++ .../codeception/_support/AcceptanceTester.php | 28 +++++++++++++++ tests/codeception/_support/UnitTester.php | 14 ++++++++ .../_support/_generated/.gitignore | 4 +++ tests/codeception/acceptance.suite.yml | 25 +++++++++++++ .../codeception/acceptance/WhitelabelCest.php | 17 +++++++++ tests/codeception/acceptance/_bootstrap.php | 6 ++++ tests/codeception/config/unit.php | 3 ++ tests/codeception/unit.suite.yml | 14 ++++++++ tests/codeception/unit/WhitelabelTest.php | 15 ++++++++ tests/codeception/unit/_bootstrap.php | 6 ++++ tests/config/common.php | 5 +++ tests/config/test.php | 11 ++++++ tests/config/unit.php | 5 +++ 16 files changed, 215 insertions(+) create mode 100644 tests/codeception.yml create mode 100644 tests/codeception/_bootstrap.php create mode 100644 tests/codeception/_output/.gitignore create mode 100644 tests/codeception/_support/AcceptanceTester.php create mode 100644 tests/codeception/_support/UnitTester.php create mode 100644 tests/codeception/_support/_generated/.gitignore create mode 100644 tests/codeception/acceptance.suite.yml create mode 100644 tests/codeception/acceptance/WhitelabelCest.php create mode 100644 tests/codeception/acceptance/_bootstrap.php create mode 100644 tests/codeception/config/unit.php create mode 100644 tests/codeception/unit.suite.yml create mode 100644 tests/codeception/unit/WhitelabelTest.php create mode 100644 tests/codeception/unit/_bootstrap.php create mode 100644 tests/config/common.php create mode 100644 tests/config/test.php create mode 100644 tests/config/unit.php 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 @@ + ['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 @@ + Date: Tue, 23 Apr 2024 17:00:52 +0200 Subject: [PATCH 3/7] Unit test --- ...{WhitelabelCest.php => TextEditorCest.php} | 0 tests/codeception/unit/TextEditorTest.php | 43 +++++++++++++++++++ tests/codeception/unit/WhitelabelTest.php | 15 ------- 3 files changed, 43 insertions(+), 15 deletions(-) rename tests/codeception/acceptance/{WhitelabelCest.php => TextEditorCest.php} (100%) create mode 100644 tests/codeception/unit/TextEditorTest.php delete mode 100644 tests/codeception/unit/WhitelabelTest.php diff --git a/tests/codeception/acceptance/WhitelabelCest.php b/tests/codeception/acceptance/TextEditorCest.php similarity index 100% rename from tests/codeception/acceptance/WhitelabelCest.php rename to tests/codeception/acceptance/TextEditorCest.php diff --git a/tests/codeception/unit/TextEditorTest.php b/tests/codeception/unit/TextEditorTest.php new file mode 100644 index 0000000..e18e309 --- /dev/null +++ b/tests/codeception/unit/TextEditorTest.php @@ -0,0 +1,43 @@ +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->assertTrue($module->canView($testFile)); + $this->assertTrue($module->canEdit($testFile)); + + $testFile->mime_type = 'image/jpeg'; + + $this->assertFalse($module->canView($testFile)); + $this->assertFalse($module->canEdit($testFile)); + } +} diff --git a/tests/codeception/unit/WhitelabelTest.php b/tests/codeception/unit/WhitelabelTest.php deleted file mode 100644 index 554be47..0000000 --- a/tests/codeception/unit/WhitelabelTest.php +++ /dev/null @@ -1,15 +0,0 @@ - Date: Wed, 24 Apr 2024 14:02:27 +0200 Subject: [PATCH 4/7] Acceptance test --- .../codeception/acceptance/TextEditorCest.php | 46 +++++++++++++++++++ tests/codeception/unit/TextEditorTest.php | 4 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/codeception/acceptance/TextEditorCest.php b/tests/codeception/acceptance/TextEditorCest.php index de9da1c..3ace559 100644 --- a/tests/codeception/acceptance/TextEditorCest.php +++ b/tests/codeception/acceptance/TextEditorCest.php @@ -13,5 +13,51 @@ class TextEditorCest { public function testTextEditor(AcceptanceTester $I) { + $I->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->fillField('#fileupdate-newfilecontent', 'test'); + $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/unit/TextEditorTest.php b/tests/codeception/unit/TextEditorTest.php index e18e309..816d790 100644 --- a/tests/codeception/unit/TextEditorTest.php +++ b/tests/codeception/unit/TextEditorTest.php @@ -7,7 +7,6 @@ namespace text_editor; -use humhub\modules\file\models\File; use humhub\modules\text_editor\models\CreateFile; use humhub\modules\text_editor\models\forms\ConfigForm; use humhub\modules\text_editor\Module; @@ -32,11 +31,14 @@ public function testTextEditor() $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)); } From 6fa52226a7ead4e3dd0f2bd8df18cea3222c32be Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Wed, 24 Apr 2024 14:10:48 +0200 Subject: [PATCH 5/7] Test v1.10 --- .github/workflows/php-test-v1.10.yml | 12 ++++++++++++ tests/codeception/acceptance/TextEditorCest.php | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/php-test-v1.10.yml diff --git a/.github/workflows/php-test-v1.10.yml b/.github/workflows/php-test-v1.10.yml new file mode 100644 index 0000000..c7c8b8f --- /dev/null +++ b/.github/workflows/php-test-v1.10.yml @@ -0,0 +1,12 @@ +name: PHP Codeception Tests - v1.10 + +on: + push: + schedule: + - cron: "0 0 * * 0" + +jobs: + tests: + uses: humhub/actions/.github/workflows/module-tests-v1.10.yml@main + with: + module-id: text-editor diff --git a/tests/codeception/acceptance/TextEditorCest.php b/tests/codeception/acceptance/TextEditorCest.php index 3ace559..b340d52 100644 --- a/tests/codeception/acceptance/TextEditorCest.php +++ b/tests/codeception/acceptance/TextEditorCest.php @@ -31,7 +31,6 @@ public function testTextEditor(AcceptanceTester $I) $I->click('Save'); $I->waitForText('Edit file: Test file name.tst'); - $I->fillField('#fileupdate-newfilecontent', 'test'); $I->executeJS('document.querySelectorAll("div.CodeMirror")[0].CodeMirror.setValue("Test\r\nLine 2")'); $I->click('Save'); $I->seeSuccess(); From ffdf97afd94584e5c671f6cf76a47b3d3ff6d498 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Wed, 24 Apr 2024 14:20:56 +0200 Subject: [PATCH 6/7] Fix for v1.15 --- Module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()); } From 24b2c8c9a3cc8492019ea62a3b1f8b2f4ebce617 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Thu, 25 Apr 2024 08:23:44 +0200 Subject: [PATCH 7/7] Remove tests of v1.10 --- .github/workflows/php-test-v1.10.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .github/workflows/php-test-v1.10.yml diff --git a/.github/workflows/php-test-v1.10.yml b/.github/workflows/php-test-v1.10.yml deleted file mode 100644 index c7c8b8f..0000000 --- a/.github/workflows/php-test-v1.10.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: PHP Codeception Tests - v1.10 - -on: - push: - schedule: - - cron: "0 0 * * 0" - -jobs: - tests: - uses: humhub/actions/.github/workflows/module-tests-v1.10.yml@main - with: - module-id: text-editor