From 2f8623264ca90e4d57ba7fa0a1479276f6c7d1f1 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Wed, 7 Apr 2021 17:06:11 +0300 Subject: [PATCH] Fix loading of fixture spaces on tests (#5002) * Fix loading of fixture spaces on tests * Update CHANGELOG.md --- CHANGELOG.md | 1 + .../tests/codeception/_support/BaseTester.php | 27 ++++++++++++------- .../codeception/_support/FunctionalTester.php | 20 +++++++------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8b87f6d61..a8abb613f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ HumHub Changelog - Enh #4972: Fix enabling to send notification on remove user from group - Fix #4985: Fix Activity Mail QueryParams on console mode - Fix #4989: Translate profile field title in admin list +- Fix #5002: Fix loading of fixture spaces on tests 1.8.1 (March 12, 2021) diff --git a/protected/humhub/tests/codeception/_support/BaseTester.php b/protected/humhub/tests/codeception/_support/BaseTester.php index e239e230f0..61ac960686 100644 --- a/protected/humhub/tests/codeception/_support/BaseTester.php +++ b/protected/humhub/tests/codeception/_support/BaseTester.php @@ -19,16 +19,25 @@ class BaseTester extends \Codeception\Actor public function getFixtureSpace(int $index) : ?Space { - if (method_exists($this, 'haveFixtures') && method_exists($this, 'grabFixture')) { - $this->haveFixtures(['space' => SpaceFixture::class]); - return $this->grabFixture('space', $index); - } else { - // Acceptance tests have no the methods above, try to get spaces from DB instead: - if (!isset($this->spaces)) { - $this->spaces = Space::find()->orderBy('id')->all(); - } - return isset($this->spaces[$index]) ? $this->spaces[$index] : null; + if (isset($this->spaces[$index])) { + return $this->spaces[$index]; } + + if (method_exists($this, 'haveFixtures') && method_exists($this, 'grabFixture')) { + if (!isset($this->spaces)) { + // Don't try to load spaces twice because it is delete all space records from related tables + $this->haveFixtures(['space' => SpaceFixture::class]); + } + $this->spaces[$index] = $this->grabFixture('space', $index); + } else if (!isset($this->spaces)) { + // Acceptance tests have no the methods above, try to get spaces from DB instead: + $this->spaces = Space::find()->orderBy('id')->all(); + if (!isset($this->spaces[$index])) { + $this->spaces[$index] = null; + } + } + + return $this->spaces[$index]; } public function getFixtureSpaceGuid(int $index) : string diff --git a/protected/humhub/tests/codeception/_support/FunctionalTester.php b/protected/humhub/tests/codeception/_support/FunctionalTester.php index 5f39fd96fd..eb61870f78 100644 --- a/protected/humhub/tests/codeception/_support/FunctionalTester.php +++ b/protected/humhub/tests/codeception/_support/FunctionalTester.php @@ -235,29 +235,31 @@ class FunctionalTester extends BaseTester $this->amOnSpace(4, $path, $params, $post); } - public function amOnSpace($guid, $path = '/space/space', $params = [], $post = false) + public function amOnSpace($spaceOrIndexOrGuid, $path = '/space/space', $params = [], $post = false) { - if(is_bool($params)) { + if (is_bool($params)) { $post = $params; $params = []; } - if(!$path) { + if (!$path) { $path = '/space/space'; } - if(is_int($guid)) { - $guid = $this->getFixtureSpaceGuid(--$guid); - } else if($guid instanceof Space) { - $guid = $guid->guid; + if(is_int($spaceOrIndexOrGuid)) { + $guid = $this->getFixtureSpaceGuid(--$spaceOrIndexOrGuid); + } else if(is_string($spaceOrIndexOrGuid)) { + $guid = $spaceOrIndexOrGuid; + } else if($spaceOrIndexOrGuid instanceof Space) { + $guid = $spaceOrIndexOrGuid->guid; } else { $guid = ''; } $params['cguid'] = $guid; - if($post) { - $route = array_merge([$path], $params); + if ($post) { + $route = array_merge([$path], $params); $this->sendAjaxPostRequest(Url::toRoute($route), (is_array($post) ? $post : [])); } else { $this->amOnRoute($path, $params);