Skip to content

Commit

Permalink
Merge pull request #24 from humhub/enh/23-github-actions
Browse files Browse the repository at this point in the history
Add GitHub Actions
  • Loading branch information
luke- authored Apr 25, 2024
2 parents 4c245d7 + 24b2c8c commit d57a624
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .github/workflows/marketplace-upload.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .github/workflows/php-test-develop.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .github/workflows/php-test-master.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .github/workflows/php-test-next.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
23 changes: 23 additions & 0 deletions tests/codeception.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions tests/codeception/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

/*
* This is the initial test bootstrap, which will load the default test bootstrap from the humhub core
*/

$testRoot = dirname(__DIR__);

\Codeception\Configuration::append(['test_root' => $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/<environment>/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';
4 changes: 4 additions & 0 deletions tests/codeception/_output/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
28 changes: 28 additions & 0 deletions tests/codeception/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace text_editor;

/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \AcceptanceTester
{
use _generated\AcceptanceTesterActions;
}
14 changes: 14 additions & 0 deletions tests/codeception/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace text_editor;

use tests\codeception\_support\HumHubDbTestCase;

class UnitTester extends HumHubDbTestCase
{
}
4 changes: 4 additions & 0 deletions tests/codeception/_support/_generated/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
25 changes: 25 additions & 0 deletions tests/codeception/acceptance.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Codeception Test Suite Configuration

# suite for acceptance tests.
# perform tests in browser using the Selenium-like tools.
# powered by Mink (http://mink.behat.org).
# (tip: that's what your customer will see).
# (tip: test your ajax and javascript by one of Mink drivers).

# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- tests\codeception\_support\WebHelper
- tests\codeception\_support\DynamicFixtureHelper
config:
WebDriver:
url: 'http://localhost:8080/'
browser: chrome
restart: true
port: 4444
capabilities:
chromeOptions:
args: ["--lang=en-US"]
62 changes: 62 additions & 0 deletions tests/codeception/acceptance/TextEditorCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace text_editor\acceptance;

use text_editor\AcceptanceTester;

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->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");
}
}
6 changes: 6 additions & 0 deletions tests/codeception/acceptance/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
/**
* Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten
* in @tests/config/functional.php
*/
require Yii::getAlias('@humhubTests/codeception/acceptance/_bootstrap.php');
3 changes: 3 additions & 0 deletions tests/codeception/config/unit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

return \tests\codeception\_support\HumHubTestConfiguration::getSuiteConfig('unit');
14 changes: 14 additions & 0 deletions tests/codeception/unit.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Codeception Test Suite Configuration

# suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

class_name: UnitTester
modules:
enabled:
- tests\codeception\_support\CodeHelper
- Yii2
config:
Yii2:
configFile: 'codeception/config/unit.php'
transaction: false
45 changes: 45 additions & 0 deletions tests/codeception/unit/TextEditorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace text_editor;

use humhub\modules\text_editor\models\CreateFile;
use humhub\modules\text_editor\models\forms\ConfigForm;
use humhub\modules\text_editor\Module;
use Yii;

class TextEditorTest extends UnitTester
{
public function testTextEditor()
{
/* @var Module $module */
$module = Yii::$app->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));
}
}
6 changes: 6 additions & 0 deletions tests/codeception/unit/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
/**
* Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten
* in @tests/config/functional.php
*/
require Yii::getAlias('@humhubTests/codeception/unit/_bootstrap.php');
5 changes: 5 additions & 0 deletions tests/config/common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
/**
* This config is shared by all suites (unit/functional/acceptance) and can be overwritten by a suite config (e.g. functional.php)
*/
return [];
11 changes: 11 additions & 0 deletions tests/config/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

return [
'modules' => ['text-editor'],
'fixtures' => ['default'],
];
5 changes: 5 additions & 0 deletions tests/config/unit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
/**
* Here you can overwrite your functional humhub config. The default config resiedes in @humhubTests/codeception/config/config.php
*/
return [];

0 comments on commit d57a624

Please sign in to comment.