Fix loading of fixture spaces on tests (#5002)

* Fix loading of fixture spaces on tests

* Update CHANGELOG.md
This commit is contained in:
Yuriy Bakhtin 2021-04-07 17:06:11 +03:00 committed by GitHub
parent b8b48e81af
commit 2f8623264c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 18 deletions

View File

@ -12,6 +12,7 @@ HumHub Changelog
- Enh #4972: Fix enabling to send notification on remove user from group - Enh #4972: Fix enabling to send notification on remove user from group
- Fix #4985: Fix Activity Mail QueryParams on console mode - Fix #4985: Fix Activity Mail QueryParams on console mode
- Fix #4989: Translate profile field title in admin list - Fix #4989: Translate profile field title in admin list
- Fix #5002: Fix loading of fixture spaces on tests
1.8.1 (March 12, 2021) 1.8.1 (March 12, 2021)

View File

@ -19,16 +19,25 @@ class BaseTester extends \Codeception\Actor
public function getFixtureSpace(int $index) : ?Space public function getFixtureSpace(int $index) : ?Space
{ {
if (method_exists($this, 'haveFixtures') && method_exists($this, 'grabFixture')) { if (isset($this->spaces[$index])) {
$this->haveFixtures(['space' => SpaceFixture::class]); return $this->spaces[$index];
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 (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 public function getFixtureSpaceGuid(int $index) : string

View File

@ -235,29 +235,31 @@ class FunctionalTester extends BaseTester
$this->amOnSpace(4, $path, $params, $post); $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; $post = $params;
$params = []; $params = [];
} }
if(!$path) { if (!$path) {
$path = '/space/space'; $path = '/space/space';
} }
if(is_int($guid)) { if(is_int($spaceOrIndexOrGuid)) {
$guid = $this->getFixtureSpaceGuid(--$guid); $guid = $this->getFixtureSpaceGuid(--$spaceOrIndexOrGuid);
} else if($guid instanceof Space) { } else if(is_string($spaceOrIndexOrGuid)) {
$guid = $guid->guid; $guid = $spaceOrIndexOrGuid;
} else if($spaceOrIndexOrGuid instanceof Space) {
$guid = $spaceOrIndexOrGuid->guid;
} else { } else {
$guid = ''; $guid = '';
} }
$params['cguid'] = $guid; $params['cguid'] = $guid;
if($post) { if ($post) {
$route = array_merge([$path], $params); $route = array_merge([$path], $params);
$this->sendAjaxPostRequest(Url::toRoute($route), (is_array($post) ? $post : [])); $this->sendAjaxPostRequest(Url::toRoute($route), (is_array($post) ? $post : []));
} else { } else {
$this->amOnRoute($path, $params); $this->amOnRoute($path, $params);