Bootstrap email-editor integration tests
I tried to minimize the code repetition. [MAILPOET-6216]
This commit is contained in:
@ -1,13 +1,9 @@
|
||||
namespace: Tests
|
||||
support_namespace: Support
|
||||
paths:
|
||||
actor_suffix: Tester
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
envs: tests/_envs
|
||||
bootstrap: _bootstrap.php
|
||||
settings:
|
||||
colors: true
|
||||
memory_limit: 1024M
|
||||
|
@ -4,7 +4,11 @@
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"MailPoet\\EmailEditor\\": "src/",
|
||||
"MailPoet\\EmailEditor\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"EmailEditor\\": "tests/unit/"
|
||||
}
|
||||
},
|
||||
@ -23,6 +27,7 @@
|
||||
"sort-packages": true
|
||||
},
|
||||
"scripts": {
|
||||
"unit-test": "vendor/bin/codecept run unit"
|
||||
"unit-test": "vendor/bin/codecept run unit",
|
||||
"integration-test": "cd ../../../tests_env/docker && COMPOSE_HTTP_TIMEOUT=200 docker compose run -e SKIP_DEPS=1 -e SKIP_PLUGINS=1 -e PACKAGE_NAME=email-editor codeception_integration"
|
||||
}
|
||||
}
|
||||
|
36
packages/php/email-editor/composer.lock
generated
36
packages/php/email-editor/composer.lock
generated
@ -170,22 +170,22 @@
|
||||
},
|
||||
{
|
||||
"name": "codeception/lib-asserts",
|
||||
"version": "2.0.1",
|
||||
"version": "1.13.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Codeception/lib-asserts.git",
|
||||
"reference": "78c55044611437988b54e1daecf13f247a742bf8"
|
||||
"reference": "184231d5eab66bc69afd6b9429344d80c67a33b6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Codeception/lib-asserts/zipball/78c55044611437988b54e1daecf13f247a742bf8",
|
||||
"reference": "78c55044611437988b54e1daecf13f247a742bf8",
|
||||
"url": "https://api.github.com/repos/Codeception/lib-asserts/zipball/184231d5eab66bc69afd6b9429344d80c67a33b6",
|
||||
"reference": "184231d5eab66bc69afd6b9429344d80c67a33b6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"codeception/phpunit-wrapper": "^7.7.1 | ^8.0.3 | ^9.0",
|
||||
"codeception/phpunit-wrapper": ">6.0.15 <6.1.0 | ^6.6.1 | ^7.7.1 | ^8.0.3 | ^9.0",
|
||||
"ext-dom": "*",
|
||||
"php": "^7.4 | ^8.0"
|
||||
"php": ">=5.6.0 <9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@ -218,31 +218,31 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Codeception/lib-asserts/issues",
|
||||
"source": "https://github.com/Codeception/lib-asserts/tree/2.0.1"
|
||||
"source": "https://github.com/Codeception/lib-asserts/tree/1.13.2"
|
||||
},
|
||||
"time": "2022-09-27T06:17:39+00:00"
|
||||
"time": "2020-10-21T16:26:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "codeception/module-asserts",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Codeception/module-asserts.git",
|
||||
"reference": "313673c35de00ad337d3b5f895a1998695d3b537"
|
||||
"reference": "ef4a27087b09bf3c3b88fa9025e3179848541a79"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Codeception/module-asserts/zipball/313673c35de00ad337d3b5f895a1998695d3b537",
|
||||
"reference": "313673c35de00ad337d3b5f895a1998695d3b537",
|
||||
"url": "https://api.github.com/repos/Codeception/module-asserts/zipball/ef4a27087b09bf3c3b88fa9025e3179848541a79",
|
||||
"reference": "ef4a27087b09bf3c3b88fa9025e3179848541a79",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"codeception/codeception": "^4.1 | *@dev",
|
||||
"codeception/lib-asserts": "^2.0",
|
||||
"php": "^7.4 | ^8.0"
|
||||
"codeception/codeception": "*@dev",
|
||||
"codeception/lib-asserts": "^1.13.1",
|
||||
"php": "^7.4 || ^8.0"
|
||||
},
|
||||
"conflict": {
|
||||
"codeception/codeception": "<4.1"
|
||||
"codeception/codeception": "<4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@ -275,9 +275,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Codeception/module-asserts/issues",
|
||||
"source": "https://github.com/Codeception/module-asserts/tree/2.0.1"
|
||||
"source": "https://github.com/Codeception/module-asserts/tree/2.0.0"
|
||||
},
|
||||
"time": "2021-12-18T17:10:04+00:00"
|
||||
"time": "2021-11-30T00:38:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "codeception/phpunit-wrapper",
|
||||
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* 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 IntegrationTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\IntegrationTesterActions;
|
||||
|
||||
private $wpTermIds = [];
|
||||
|
||||
private $createdCommentIds = [];
|
||||
|
||||
private $posts = [];
|
||||
|
||||
public function createPost(array $params): \WP_Post {
|
||||
$postId = wp_insert_post($params);
|
||||
if ($postId instanceof WP_Error) {
|
||||
throw new \Exception('Failed to create post');
|
||||
}
|
||||
$post = get_post($postId);
|
||||
if (!$post instanceof WP_Post) {
|
||||
throw new \Exception('Failed to fetch the post');
|
||||
}
|
||||
$this->posts[] = $post;
|
||||
return $post;
|
||||
}
|
||||
|
||||
public function cleanup() {
|
||||
$this->deleteWordPressTerms();
|
||||
$this->deleteCreatedComments();
|
||||
$this->deletePosts();
|
||||
}
|
||||
|
||||
private function deletePosts() {
|
||||
foreach ($this->posts as $post) {
|
||||
wp_delete_post($post->ID, true);
|
||||
}
|
||||
}
|
||||
|
||||
private function deleteWordPressTerms(): void {
|
||||
foreach ($this->wpTermIds as $taxonomy => $termIds) {
|
||||
foreach ($termIds as $termId) {
|
||||
wp_delete_term($termId, $taxonomy);
|
||||
}
|
||||
}
|
||||
$this->wpTermIds = [];
|
||||
}
|
||||
|
||||
private function deleteCreatedComments() {
|
||||
foreach ($this->createdCommentIds as $commentId) {
|
||||
wp_delete_comment($commentId, true);
|
||||
}
|
||||
$this->createdCommentIds = [];
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
|
10
packages/php/email-editor/tests/integration.suite.yml
Normal file
10
packages/php/email-editor/tests/integration.suite.yml
Normal file
@ -0,0 +1,10 @@
|
||||
# Codeception Test Suite Configuration
|
||||
#
|
||||
# Suite for unit (internal) tests.
|
||||
|
||||
actor: IntegrationTester
|
||||
bootstrap: _bootstrap.php
|
||||
modules:
|
||||
enabled:
|
||||
- Asserts
|
||||
error_level: E_ALL
|
178
packages/php/email-editor/tests/integration/_bootstrap.php
Normal file
178
packages/php/email-editor/tests/integration/_bootstrap.php
Normal file
@ -0,0 +1,178 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
use Codeception\Stub;
|
||||
use MailPoet\EmailEditor\Container;
|
||||
use MailPoet\EmailEditor\Engine\EmailApiController;
|
||||
use MailPoet\EmailEditor\Engine\EmailEditor;
|
||||
use MailPoet\EmailEditor\Engine\Patterns\Patterns;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\BlocksRegistry;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\ContentRenderer;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\HighlightingPostprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Postprocessors\VariablesPostprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\BlocksWidthPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\CleanupPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\SpacingPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\Preprocessors\TypographyPreprocessor;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\ContentRenderer\ProcessManager;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\Renderer;
|
||||
use MailPoet\EmailEditor\Engine\SettingsController;
|
||||
use MailPoet\EmailEditor\Engine\Templates\TemplatePreview;
|
||||
use MailPoet\EmailEditor\Engine\Templates\Templates;
|
||||
use MailPoet\EmailEditor\Engine\Templates\Utils;
|
||||
use MailPoet\EmailEditor\Engine\ThemeController;
|
||||
use MailPoet\EmailEditor\Integrations\Core\Initializer;
|
||||
use MailPoet\EmailEditor\Integrations\MailPoet\Blocks\BlockTypesController;
|
||||
use MailPoet\EmailEditor\Utils\CdnAssetUrl;
|
||||
|
||||
if ((boolean)getenv('MULTISITE') === true) {
|
||||
// REQUEST_URI needs to be set for WP to load the proper subsite where MailPoet is activated
|
||||
$_SERVER['REQUEST_URI'] = '/' . getenv('WP_TEST_MULTISITE_SLUG');
|
||||
$wpLoadFile = getenv('WP_ROOT_MULTISITE') . '/wp-load.php';
|
||||
} else {
|
||||
$wpLoadFile = getenv('WP_ROOT') . '/wp-load.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting env from .evn file
|
||||
* Note that the following are override in the docker-compose file
|
||||
* WP_ROOT, WP_ROOT_MULTISITE, WP_TEST_MULTISITE_SLUG
|
||||
*/
|
||||
$console = new \Codeception\Lib\Console\Output([]);
|
||||
$console->writeln('Loading WP core... (' . $wpLoadFile . ')');
|
||||
require_once($wpLoadFile);
|
||||
|
||||
/**
|
||||
* @property IntegrationTester $tester
|
||||
*/
|
||||
abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore
|
||||
|
||||
public Container $diContainer;
|
||||
|
||||
protected $backupGlobals = false;
|
||||
protected $backupStaticAttributes = false;
|
||||
protected $runTestInSeparateProcess = false;
|
||||
protected $preserveGlobalState = false;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->initContainer();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function checkValidHTML(string $html): void {
|
||||
$dom = new \DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML($html);
|
||||
|
||||
// Check for errors during parsing
|
||||
$errors = libxml_get_errors();
|
||||
libxml_clear_errors();
|
||||
|
||||
$this->assertEmpty($errors, 'HTML is not valid: ' . $html);
|
||||
}
|
||||
|
||||
public function getServiceWithOverrides(string $id, array $overrides) {
|
||||
$instance = $this->diContainer->get($id);
|
||||
return Stub::copy($instance, $overrides);
|
||||
}
|
||||
|
||||
protected function initContainer(): void {
|
||||
$container = new Container();
|
||||
// Start: MailPoet plugin dependencies
|
||||
$container->set(Initializer::class, function() {
|
||||
return new Initializer();
|
||||
});
|
||||
$container->set(CdnAssetUrl::class, function() {
|
||||
return new CdnAssetUrl('http://localhost');
|
||||
});
|
||||
$container->set(EmailApiController::class, function() {
|
||||
return new EmailApiController();
|
||||
});
|
||||
$container->set(BlockTypesController::class, function() {
|
||||
return $this->createMock(BlockTypesController::class);
|
||||
});
|
||||
// End: MailPoet plugin dependencies
|
||||
$container->set(Utils::class, function() {
|
||||
return new Utils();
|
||||
});
|
||||
$container->set(ThemeController::class, function() {
|
||||
return new ThemeController();
|
||||
});
|
||||
$container->set(SettingsController::class, function ($container) {
|
||||
return new SettingsController($container->get(ThemeController::class));
|
||||
});
|
||||
$container->set(SettingsController::class, function ($container) {
|
||||
return new SettingsController($container->get(ThemeController::class));
|
||||
});
|
||||
$container->set(Templates::class, function ($container) {
|
||||
return new Templates($container->get(Utils::class));
|
||||
});
|
||||
$container->set(TemplatePreview::class, function ($container) {
|
||||
return new TemplatePreview(
|
||||
$container->get(ThemeController::class),
|
||||
$container->get(Templates::class),
|
||||
);
|
||||
});
|
||||
$container->set(Patterns::class, function ($container) {
|
||||
return new Patterns(
|
||||
$container->get(CdnAssetUrl::class),
|
||||
);
|
||||
});
|
||||
$container->set(CleanupPreprocessor::class, function () {
|
||||
return new CleanupPreprocessor();
|
||||
});
|
||||
$container->set(BlocksWidthPreprocessor::class, function () {
|
||||
return new BlocksWidthPreprocessor();
|
||||
});
|
||||
$container->set(TypographyPreprocessor::class, function ($container) {
|
||||
return new TypographyPreprocessor($container->get(SettingsController::class));
|
||||
});
|
||||
$container->set(SpacingPreprocessor::class, function () {
|
||||
return new SpacingPreprocessor();
|
||||
});
|
||||
$container->set(HighlightingPostprocessor::class, function () {
|
||||
return new HighlightingPostprocessor();
|
||||
});
|
||||
$container->set(VariablesPostprocessor::class, function ($container) {
|
||||
return new VariablesPostprocessor($container->get(ThemeController::class));
|
||||
});
|
||||
$container->set(ProcessManager::class, function ($container) {
|
||||
return new ProcessManager(
|
||||
$container->get(CleanupPreprocessor::class),
|
||||
$container->get(BlocksWidthPreprocessor::class),
|
||||
$container->get(TypographyPreprocessor::class),
|
||||
$container->get(SpacingPreprocessor::class),
|
||||
$container->get(HighlightingPostprocessor::class),
|
||||
$container->get(VariablesPostprocessor::class),
|
||||
);
|
||||
});
|
||||
$container->set(BlocksRegistry::class, function() {
|
||||
return new BlocksRegistry();
|
||||
});
|
||||
$container->set(ContentRenderer::class, function ($container) {
|
||||
return new ContentRenderer(
|
||||
$container->get(ProcessManager::class),
|
||||
$container->get(BlocksRegistry::class),
|
||||
$container->get(SettingsController::class),
|
||||
$container->get(ThemeController::class),
|
||||
);
|
||||
});
|
||||
$container->set(Renderer::class, function ($container) {
|
||||
return new Renderer(
|
||||
$container->get(ContentRenderer::class),
|
||||
$container->get(Templates::class),
|
||||
$container->get(ThemeController::class),
|
||||
);
|
||||
});
|
||||
$container->set(EmailEditor::class, function ($container) {
|
||||
return new EmailEditor(
|
||||
$container->get(EmailApiController::class),
|
||||
$container->get(Templates::class),
|
||||
$container->get(TemplatePreview::class),
|
||||
$container->get(Patterns::class),
|
||||
$container->get(SettingsController::class),
|
||||
);
|
||||
});
|
||||
|
||||
$this->diContainer = $container;
|
||||
}
|
||||
}
|
@ -219,11 +219,15 @@ mysql -u wordpress -pwordpress wordpress -h mysql -e "SELECT @@global.sql_mode"
|
||||
# print tables info
|
||||
mysql -u wordpress -pwordpress wordpress -h mysql -e "SELECT TABLE_NAME, ENGINE, TABLE_COLLATION FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'wordpress'"
|
||||
|
||||
if [[ $PACKAGE_NAME == "email-editor" ]]; then
|
||||
cd /wp-core/wp-content/plugins/packages/php/email-editor
|
||||
else
|
||||
if [[ $WITH_PREMIUM == "1" ]]; then
|
||||
cd /wp-core/wp-content/plugins/mailpoet-premium
|
||||
else
|
||||
cd /wp-core/wp-content/plugins/mailpoet
|
||||
fi
|
||||
fi
|
||||
|
||||
/wp-core/wp-content/plugins/mailpoet/vendor/bin/codecept run $TEST_TYPE $@ -vvv
|
||||
exitcode=$?
|
||||
|
Reference in New Issue
Block a user