Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Apr 23, 2024
1 parent b1e39cb commit 0939d71
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 0 deletions.
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"]
17 changes: 17 additions & 0 deletions tests/codeception/acceptance/WhitelabelCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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)
{
}
}
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
15 changes: 15 additions & 0 deletions tests/codeception/unit/WhitelabelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace text_editor;

class TextEditorTest extends UnitTester
{
public function testTextEditor()
{
}
}
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 0939d71

Please sign in to comment.