Skip to content

Commit

Permalink
Fix humhub test case would fail on skipped tests (humhub#6516)
Browse files Browse the repository at this point in the history
* Fix skipped test handling

* Fix error while sending mails from the queue

```
- ReadableContentQueryTest: Global content guest non guest mode  Destroying application
  Starting application
  [ConnectionWatcher] watching new connections
  [Fixtures] Loading fixtures
  [ConnectionWatcher] watching new connections
  [ConnectionWatcher] no longer watching new connections
  [ConnectionWatcher] closing all (0) connections
  [Fixtures] Done
  [yii\web\Session::open] 'Session started'
  [queue] 'Could not execute queued job! Message: Argument 2 passed to Symfony\\Component\\Mime\\Address::__construct() must be of the type string, null given, called in /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-symfonymailer/src/Message.php on line 368 Trace:#0 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-symfonymailer/src/Message.php(368): Symfony\\Component\\Mime\\Address->__construct()
  humhub#1 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-symfonymailer/src/Message.php(51): yii\\symfonymailer\\Message->convertStringsToAddresses()
  humhub#2 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/targets/MailTarget.php(71): yii\\symfonymailer\\Message->setFrom()
  humhub#3 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/targets/BaseTarget.php(161): humhub\\modules\\notification\\targets\\MailTarget->handle()
  humhub#4 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/components/NotificationManager.php(101): humhub\\modules\\notification\\targets\\BaseTarget->send()
  humhub#5 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/jobs/SendBulkNotification.php(38): humhub\\modules\\notification\\components\\NotificationManager->sendBulk()
  humhub#6 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/queue/ActiveJob.php(33): humhub\\modules\\notification\\jobs\\SendBulkNotification->run()
  humhub#7 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-queue/src/Queue.php(246): humhub\\modules\\queue\\ActiveJob->execute()
  humhub#8 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/queue/driver/Instant.php(31): yii\\queue\\Queue->handleMessage()
  humhub#9 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-queue/src/Queue.php(196): humhub\\modules\\queue\\driver\\Instant->pushMessage()
  humhub#10 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/components/BaseNotification.php(210): yii\\queue\\Queue->push()
  humhub#11 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/models/Content.php(370): humhub\\modules\\notification\\components\\BaseNotification->sendBulk()
  humhub#12 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/models/Content.php(321): humhub\\modules\\content\\models\\Content->notifyContentCreated()
  humhub#13 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/models/Content.php(268): humhub\\modules\\content\\models\\Content->processNewContent()
  humhub#14 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/ActiveRecord.php(615): humhub\\modules\\content\\models\\Content->afterSave()
  humhub#15 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/ActiveRecord.php(570): yii\\db\\ActiveRecord->insertInternal()
  humhub#16 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/BaseActiveRecord.php(676): yii\\db\\ActiveRecord->insert()
  humhub#17 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/components/ContentActiveRecord.php(476): yii\\db\\BaseActiveRecord->save()
  humhub#18 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/post/models/Post.php(97): humhub\\modules\\content\\components\\ContentActiveRecord->afterSave()
  humhub#19 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/ActiveRecord.php(615): humhub\\modules\\post\\models\\Post->afterSave()
  humhub#20 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/ActiveRecord.php(570): yii\\db\\ActiveRecord->insertInternal()
  humhub#21 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/BaseActiveRecord.php(676): yii\\db\\ActiveRecord->insert()
  humhub#22 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/tests/codeception/unit/ReadableContentQueryTest.php(70): yii\\db\\BaseActiveRecord->save()
  humhub#23 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Test/Unit.php(57): tests\\codeception\\unit\\modules\\content\\ReadableContentQueryTest->_before()
  humhub#24 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/phpunit-wrapper/src/TestCase.php(12): Codeception\\Test\\Unit->_setUp()
  humhub#25 /home/mdr/projects/humhub/htdocs/protected/humhub/tests/codeception/_support/HumHubDbTestCase.php(60): Codeception\\PHPUnit\\TestCase->setUp()
  humhub#26 /home/mdr/projects/humhub/htdocs/protected/vendor/phpunit/phpunit/src/Framework/TestCase.php(1207): tests\\codeception\\_support\\HumHubDbTestCase->setUp()
  humhub#27 /home/mdr/projects/humhub/htdocs/protected/vendor/phpunit/phpunit/src/Framework/TestResult.php(728): PHPUnit\\Framework\\TestCase->runBare()
  humhub#28 /home/mdr/projects/humhub/htdocs/protected/vendor/phpunit/phpunit/src/Framework/TestCase.php(964): PHPUnit\\Framework\\TestResult->run()
  humhub#29 /home/mdr/projects/humhub/htdocs/protected/vendor/phpunit/phpunit/src/Framework/TestSuite.php(684): PHPUnit\\Framework\\TestCase->run()
  humhub#30 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/phpunit-wrapper/src/Runner.php(117): PHPUnit\\Framework\\TestSuite->run()
  humhub#31 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/SuiteManager.php(161): Codeception\\PHPUnit\\Runner->doEnhancedRun()
  humhub#32 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Codecept.php(208): Codeception\\SuiteManager->run()
  humhub#33 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Codecept.php(162): Codeception\\Codecept->runSuite()
  humhub#34 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Command/Run.php(401): Codeception\\Codecept->run()
  humhub#35 /home/mdr/projects/humhub/htdocs/protected/vendor/symfony/console/Command/Command.php(298): Codeception\\Command\\Run->execute()
  humhub#36 /home/mdr/projects/humhub/htdocs/protected/vendor/symfony/console/Application.php(1040): Symfony\\Component\\Console\\Command\\Command->run()
  humhub#37 /home/mdr/projects/humhub/htdocs/protected/vendor/symfony/console/Application.php(301): Symfony\\Component\\Console\\Application->doRunCommand()
  humhub#38 /home/mdr/projects/humhub/htdocs/protected/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun()
  humhub#39 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Application.php(117): Symfony\\Component\\Console\\Application->run()
  humhub#40 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/app.php(46): Codeception\\Application->run()
  humhub#41 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/app.php(47): {closure}()
  humhub#42 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/codecept(6): require(\'/home/mdr/proje...\')
  humhub#43 /home/mdr/projects/humhub/htdocs/protected/vendor/bin/codecept(112): include(\'/home/mdr/proje...\')
  humhub#44 {main}'
  [queue] 'Could not execute queued job! Message: Argument 2 passed to Symfony\\Component\\Mime\\Address::__construct() must be of the type string, null given, called in /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-symfonymailer/src/Message.php on line 368 Trace:#0 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-symfonymailer/src/Message.php(368): Symfony\\Component\\Mime\\Address->__construct()
  humhub#1 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-symfonymailer/src/Message.php(51): yii\\symfonymailer\\Message->convertStringsToAddresses()
  humhub#2 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/targets/MailTarget.php(71): yii\\symfonymailer\\Message->setFrom()
  humhub#3 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/targets/BaseTarget.php(161): humhub\\modules\\notification\\targets\\MailTarget->handle()
  humhub#4 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/components/NotificationManager.php(101): humhub\\modules\\notification\\targets\\BaseTarget->send()
  humhub#5 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/jobs/SendBulkNotification.php(38): humhub\\modules\\notification\\components\\NotificationManager->sendBulk()
  humhub#6 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/queue/ActiveJob.php(33): humhub\\modules\\notification\\jobs\\SendBulkNotification->run()
  humhub#7 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-queue/src/Queue.php(246): humhub\\modules\\queue\\ActiveJob->execute()
  humhub#8 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/queue/driver/Instant.php(31): yii\\queue\\Queue->handleMessage()
  humhub#9 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2-queue/src/Queue.php(196): humhub\\modules\\queue\\driver\\Instant->pushMessage()
  humhub#10 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/notification/components/BaseNotification.php(210): yii\\queue\\Queue->push()
  humhub#11 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/models/Content.php(370): humhub\\modules\\notification\\components\\BaseNotification->sendBulk()
  humhub#12 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/models/Content.php(321): humhub\\modules\\content\\models\\Content->notifyContentCreated()
  humhub#13 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/models/Content.php(268): humhub\\modules\\content\\models\\Content->processNewContent()
  humhub#14 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/ActiveRecord.php(615): humhub\\modules\\content\\models\\Content->afterSave()
  humhub#15 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/ActiveRecord.php(570): yii\\db\\ActiveRecord->insertInternal()
  humhub#16 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/BaseActiveRecord.php(676): yii\\db\\ActiveRecord->insert()
  humhub#17 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/components/ContentActiveRecord.php(476): yii\\db\\BaseActiveRecord->save()
  humhub#18 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/post/models/Post.php(97): humhub\\modules\\content\\components\\ContentActiveRecord->afterSave()
  humhub#19 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/ActiveRecord.php(615): humhub\\modules\\post\\models\\Post->afterSave()
  humhub#20 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/ActiveRecord.php(570): yii\\db\\ActiveRecord->insertInternal()
  humhub#21 /home/mdr/projects/humhub/htdocs/protected/vendor/yiisoft/yii2/db/BaseActiveRecord.php(676): yii\\db\\ActiveRecord->insert()
  humhub#22 /home/mdr/projects/humhub/htdocs/protected/humhub/modules/content/tests/codeception/unit/ReadableContentQueryTest.php(76): yii\\db\\BaseActiveRecord->save()
  humhub#23 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Test/Unit.php(57): tests\\codeception\\unit\\modules\\content\\ReadableContentQueryTest->_before()
  humhub#24 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/phpunit-wrapper/src/TestCase.php(12): Codeception\\Test\\Unit->_setUp()
  humhub#25 /home/mdr/projects/humhub/htdocs/protected/humhub/tests/codeception/_support/HumHubDbTestCase.php(60): Codeception\\PHPUnit\\TestCase->setUp()
  humhub#26 /home/mdr/projects/humhub/htdocs/protected/vendor/phpunit/phpunit/src/Framework/TestCase.php(1207): tests\\codeception\\_support\\HumHubDbTestCase->setUp()
  humhub#27 /home/mdr/projects/humhub/htdocs/protected/vendor/phpunit/phpunit/src/Framework/TestResult.php(728): PHPUnit\\Framework\\TestCase->runBare()
  humhub#28 /home/mdr/projects/humhub/htdocs/protected/vendor/phpunit/phpunit/src/Framework/TestCase.php(964): PHPUnit\\Framework\\TestResult->run()
  humhub#29 /home/mdr/projects/humhub/htdocs/protected/vendor/phpunit/phpunit/src/Framework/TestSuite.php(684): PHPUnit\\Framework\\TestCase->run()
  humhub#30 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/phpunit-wrapper/src/Runner.php(117): PHPUnit\\Framework\\TestSuite->run()
  humhub#31 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/SuiteManager.php(161): Codeception\\PHPUnit\\Runner->doEnhancedRun()
  humhub#32 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Codecept.php(208): Codeception\\SuiteManager->run()
  humhub#33 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Codecept.php(162): Codeception\\Codecept->runSuite()
  humhub#34 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Command/Run.php(401): Codeception\\Codecept->run()
  humhub#35 /home/mdr/projects/humhub/htdocs/protected/vendor/symfony/console/Command/Command.php(298): Codeception\\Command\\Run->execute()
  humhub#36 /home/mdr/projects/humhub/htdocs/protected/vendor/symfony/console/Application.php(1040): Symfony\\Component\\Console\\Command\\Command->run()
  humhub#37 /home/mdr/projects/humhub/htdocs/protected/vendor/symfony/console/Application.php(301): Symfony\\Component\\Console\\Application->doRunCommand()
  humhub#38 /home/mdr/projects/humhub/htdocs/protected/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun()
  humhub#39 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/src/Codeception/Application.php(117): Symfony\\Component\\Console\\Application->run()
  humhub#40 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/app.php(46): Codeception\\Application->run()
  humhub#41 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/app.php(47): {closure}()
  humhub#42 /home/mdr/projects/humhub/htdocs/protected/vendor/codeception/codeception/codecept(6): require(\'/home/mdr/proje...\')
  humhub#43 /home/mdr/projects/humhub/htdocs/protected/vendor/bin/codecept(112): include(\'/home/mdr/proje...\')
  humhub#44 {main}'
  [tests\codeception\_support\HumHubDbTestCase::setUp] Initializing Modules
  [tests\codeception\_support\HumHubDbTestCase::setUp] Reloading settings
  [tests\codeception\_support\HumHubDbTestCase::setUp] Flushing cache
  [tests\codeception\_support\HumHubDbTestCase::setUp] Deleting mails
  [yii\mail\BaseMailer::send] 'Sending email "Sara Tester just wrote post "Public Space Public Post" in space Space 3" to "user1@example.com"'
  [yii\mail\BaseMailer::send] 'Sending email "Sara Tester just wrote post "Public Space Private Post" in space Space 3" to "user1@example.com"'
  [yii\web\User::logout] 'User \'2\' logged out from .'
✔ ReadableContentQueryTest: Global content guest non guest mode (3.06s)
^
```

rather than

```
- ReadableContentQueryTest: Global content guest non guest mode  Destroying application
  Starting application
  [ConnectionWatcher] watching new connections
  [Fixtures] Loading fixtures
  [ConnectionWatcher] watching new connections
  [ConnectionWatcher] no longer watching new connections
  [ConnectionWatcher] closing all (0) connections
  [Fixtures] Done
  [tests\codeception\_support\HumHubDbTestCase::setUp] Initializing Modules
  [tests\codeception\_support\HumHubDbTestCase::setUp] Reloading settings
  [tests\codeception\_support\HumHubDbTestCase::setUp] Flushing cache
  [tests\codeception\_support\HumHubDbTestCase::setUp] Deleting mails
  [yii\web\Session::open] 'Session started'
  [yii\mail\BaseMailer::send] 'Sending email "Sara Tester just wrote post "Public Space Public Post" in space Space 3" to "user1@example.com"'
  [yii\mail\BaseMailer::send] 'Sending email "Sara Tester just wrote post "Public Space Private Post" in space Space 3" to "user1@example.com"'
  [yii\web\User::logout] 'User \'2\' logged out from .'
✔ ReadableContentQueryTest: Global content guest non guest mode (1.51s)
  Destroying application
  [ConnectionWatcher] no longer watching new connections
  [ConnectionWatcher] closing all (0) connections
-
```
  • Loading branch information
martin-rueegg committed Sep 26, 2023
1 parent 2a9968b commit bed9e11
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ HumHub Changelog
- Fix #6551: Migration's transaction with invalid savepoint
- Fix #6549: Empty profile field type causing an unspecific error
- Enh #6529: Add boolean return-type to `*safe*` methods in migrations
- Fix #6516: Humhub test case would fail on skipped tests
- Enh #6478: Add pseudo test class to allow population of DB with standard test data
- Enh #6480: Convert assert* and db* methods to static, in line with general usage pattern
- Enh #6505: Introduce Application interface; now also fire the `onInit` event when the web application has initialized
Expand Down
56 changes: 19 additions & 37 deletions protected/humhub/tests/codeception/_support/HumHubDbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use humhub\modules\user\tests\codeception\fixtures\UserFullFixture;
use humhub\tests\codeception\fixtures\SettingFixture;
use humhub\tests\codeception\fixtures\UrlOembedFixture;
use PHPUnit\Framework\SkippedTestError;
use TypeError;
use Yii;
use yii\db\ActiveRecord;
Expand All @@ -48,6 +49,8 @@
*/
class HumHubDbTestCase extends Unit
{
use HumHubHelperTrait;

protected $fixtureConfig;

public $appConfig = '@tests/codeception/config/unit.php';
Expand All @@ -57,54 +60,33 @@ class HumHubDbTestCase extends Unit

protected function setUp(): void
{
parent::setUp();

$webRoot = dirname(__DIR__, 2) . '/../../..';
Yii::setAlias('@webroot', realpath($webRoot));
$this->initModules();
$this->reloadSettings();
$this->flushCache();
$this->deleteMails();
}

protected function reloadSettings()
{
Yii::$app->settings->reload();

foreach (Yii::$app->modules as $module) {
if ($module instanceof \humhub\components\Module) {
$module->settings->reload();
if (Yii::$app === null) {
$c = new \ReflectionClass($this);
$m = $c->getMethod($this->getName(false));
$doc = $m->getDocComment();
if (preg_match('#@skip(.*?)\r?\n#s', $doc, $annotations)) {
throw new SkippedTestError("Test was skipped due to @skip annotation: " . (trim($annotations[1]) ?: "[No reason indicated!]"), 0);
}
return;
}
}

protected function flushCache()
{
Yii::$app->runtimeCache->flush();
RichTextToShortTextConverter::flushCache();
RichTextToHtmlConverter::flushCache();
RichTextToPlainTextConverter::flushCache();
RichTextToMarkdownConverter::flushCache();
UrlOembed::flush();
}
$webRoot = dirname(__DIR__, 2) . '/../../..';
Yii::setAlias('@webroot', realpath($webRoot));
$this->initModules(__METHOD__);
$this->reloadSettings(__METHOD__);
$this->flushCache(__METHOD__);
$this->deleteMails(__METHOD__);

protected function deleteMails()
{
$path = Yii::getAlias('@runtime/mail');
$files = glob($path . '/*'); // get all file names
foreach ($files as $file) { // iterate files
if (is_file($file)) {
unlink($file); // delete file
}
}
parent::setUp();
}

/**
* Initializes modules defined in @tests/codeception/config/test.config.php
* Note the config key in test.config.php is modules and not humhubModules!
*/
protected function initModules()
protected function initModules(?string $caller = null)
{
codecept_debug(sprintf('[%s] Initializing Modules', $caller ?? __METHOD__));
$cfg = Configuration::config();

if (!empty($cfg['humhub_modules'])) {
Expand Down
14 changes: 4 additions & 10 deletions protected/humhub/tests/codeception/_support/HumHubHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use humhub\modules\content\widgets\richtext\converter\RichTextToPlainTextConverter;
use humhub\modules\content\widgets\richtext\converter\RichTextToShortTextConverter;
use Yii;
use yii\helpers\FileHelper;
use yii\symfonymailer\Message;

/**
Expand All @@ -19,22 +20,15 @@
*/
class HumHubHelper extends Module
{
use HumHubHelperTrait;

protected $config = [];

public function _before(\Codeception\TestInterface $test)
{
Yii::$app->getUrlManager()->setScriptUrl('/index-test.php');
$this->flushCache();
}

protected function flushCache()
{
RichTextToShortTextConverter::flushCache();
RichTextToHtmlConverter::flushCache();
RichTextToPlainTextConverter::flushCache();
RichTextToMarkdownConverter::flushCache();
UrlOembed::flush();
$this->reloadSettings(__METHOD__);
$this->flushCache(__METHOD__);
}

public function fetchInviteToken($mail)
Expand Down
63 changes: 63 additions & 0 deletions protected/humhub/tests/codeception/_support/HumHubHelperTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* @link https://www.humhub.org/
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace tests\codeception\_support;

use humhub\models\UrlOembed;
use humhub\modules\content\widgets\richtext\converter\RichTextToHtmlConverter;
use humhub\modules\content\widgets\richtext\converter\RichTextToMarkdownConverter;
use humhub\modules\content\widgets\richtext\converter\RichTextToPlainTextConverter;
use humhub\modules\content\widgets\richtext\converter\RichTextToShortTextConverter;
use Yii;
use yii\helpers\FileHelper;

/**
* @since 1.15
*/
trait HumHubHelperTrait
{
protected function flushCache(?string $caller = null)
{
codecept_debug(sprintf('[%s] Flushing cache', $caller ?? __METHOD__));
$cachePath = Yii::getAlias('@runtime/cache');
if ($cachePath && is_dir($cachePath)) {
FileHelper::removeDirectory($cachePath);
}
Yii::$app->cache->flush();
Yii::$app->runtimeCache->flush();
RichTextToShortTextConverter::flushCache();
RichTextToHtmlConverter::flushCache();
RichTextToPlainTextConverter::flushCache();
RichTextToMarkdownConverter::flushCache();
UrlOembed::flush();
}

protected function reloadSettings(?string $caller = null)
{
codecept_debug(sprintf('[%s] Reloading settings', $caller ?? __METHOD__));
Yii::$app->settings->reload();

foreach (Yii::$app->modules as $module) {
if ($module instanceof \humhub\components\Module) {
$module->settings->reload();
}
}
}

protected function deleteMails(?string $caller = null)
{
codecept_debug(sprintf('[%s] Deleting mails', $caller ?? __METHOD__));
$path = Yii::getAlias('@runtime/mail');
$files = glob($path . '/*'); // get all file names
foreach ($files as $file) { // iterate files
if (is_file($file)) {
unlink($file); // delete file
}
}
}
}

0 comments on commit bed9e11

Please sign in to comment.