Migrated PostFixture to ContentActiveFixture (#6001)

* Migrated PostFixture to ContentActiveFixture

* Fixed fixture data
This commit is contained in:
Lucas Bartholemy 2022-12-30 14:18:06 +01:00 committed by GitHub
parent 943057ba7c
commit 615ec2ad09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 135 additions and 58 deletions

View File

@ -1,45 +1,9 @@
<?php
/**
* HumHub
* Copyright © 2014 The HumHub Project
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*/
return [
['id' => '1', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e21', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '1', 'visibility' => '0', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 1, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
['id' => '2', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e22', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '2', 'visibility' => '1', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 1, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
['id' => '3', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e23', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '3', 'visibility' => '0', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 2, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
['id' => '4', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e24', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '4', 'visibility' => '1', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 2, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
['id' => '5', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e25', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '5', 'visibility' => '0', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 3, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '3', 'stream_channel' => 'default'],
['id' => '6', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e26', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '6', 'visibility' => '1', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 3, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '3', 'stream_channel' => 'default'],
// Posts to Space 1 (Id: 1) of User 1 & 3
['id' => '7', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e27', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '7', 'visibility' => '1', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 4, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
['id' => '8', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e28', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '8', 'visibility' => '0', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 4, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
['id' => '9', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e29', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '9', 'visibility' => '1', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 4, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '3', 'stream_channel' => 'default'],
// Posts to Space 2 of User 2 (Public & Private)
['id' => '10', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e30', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '10', 'visibility' => '1', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
['id' => '11', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e31', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '11', 'visibility' => '0', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
['id' => '12', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e32', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '12', 'visibility' => '1', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
['id' => '13', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e33', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '13', 'visibility' => '0', 'pinned' => '0', 'archived' => '0', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
// Posts to Space 2 of User 2 (Archived)
['id' => '14', 'guid' => 'e0acdc54-13c8-4778-adc1-7302e3243e34', 'object_model' => 'humhub\modules\post\models\Post', 'object_id' => '14', 'visibility' => '1', 'pinned' => '0', 'archived' => '1', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
];
return [];

View File

@ -8,12 +8,10 @@
namespace humhub\modules\post\tests\codeception\fixtures;
use yii\test\ActiveFixture;
use tests\codeception\_support\ContentActiveFixture;
class PostFixture extends ActiveFixture
class PostFixture extends ContentActiveFixture
{
public $modelClass = 'humhub\modules\post\models\Post';
public $dataFile = '@modules/post/tests/codeception/fixtures/data/post.php';
}

View File

@ -18,22 +18,71 @@
* GNU Affero General Public License for more details.
*/
return [
['id' => '1', 'message' => 'User 1 Profile Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1'],
['id' => '2', 'message' => 'User 1 Profile Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1'],
['id' => '3', 'message' => 'User 2 Profile Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2'],
['id' => '4', 'message' => 'User 2 Profile Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2'],
['id' => '5', 'message' => 'User 3 Profile Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '3'],
['id' => '6', 'message' => 'User 3 Profile Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '3'],
['id' => '7', 'message' => 'User 1 Space 1 Post Public ', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1'],
['id' => '8', 'message' => 'User 1 Space 1 Post Private ', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1'],
['id' => '9', 'message' => 'User 3 Space 1 Post Public ', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '3'],
[
'id' => '1', 'message' => 'User 1 Profile Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1',
'content' => ['visibility' => '0', 'contentcontainer_id' => 1, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
],
[
'id' => '2', 'message' => 'User 1 Profile Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1',
'content' => ['visibility' => '1', 'contentcontainer_id' => 1, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
],
[
'id' => '3', 'message' => 'User 2 Profile Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2',
'content' => ['visibility' => '0', 'contentcontainer_id' => 2, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
],
[
'id' => '4', 'message' => 'User 2 Profile Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2',
'content' => ['visibility' => '1', 'contentcontainer_id' => 2, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
],
[
'id' => '5', 'message' => 'User 3 Profile Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '3',
'content' => ['visibility' => '0', 'contentcontainer_id' => 3, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '3', 'stream_channel' => 'default'],
],
['id' => '10', 'message' => 'User 2 Space 2 Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2'],
['id' => '11', 'message' => 'User 2 Space 2 Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2'],
// Posts to Space 1 (Id: 1) of User 1 & 3
[
'id' => '6', 'message' => 'User 3 Profile Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '3',
'content' => ['visibility' => '1', 'contentcontainer_id' => 3, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '3', 'stream_channel' => 'default'],
],
['id' => '12', 'message' => 'Admin Space 2 Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1'],
['id' => '13', 'message' => 'Admin Space 2 Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1'],
['id' => '14', 'message' => 'User 2 Space 2 Post Archived', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2'],
// Posts to Space 1 (Id: 1) of User 1 & 3
[
'id' => '7', 'message' => 'User 1 Space 1 Post Public ', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1',
'content' => ['visibility' => '1', 'contentcontainer_id' => 4, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
],
[
'id' => '8', 'message' => 'User 1 Space 1 Post Private ', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1',
'content' => ['visibility' => '0', 'contentcontainer_id' => 4, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
],
[
'id' => '9', 'message' => 'User 3 Space 1 Post Public ', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '3',
'content' => ['visibility' => '1', 'contentcontainer_id' => 4, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '3', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '3', 'stream_channel' => 'default'],
],
// Posts to Space 2 of User 2 (Public & Private)
[
'id' => '10', 'message' => 'User 2 Space 2 Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2',
'content' => ['visibility' => '1', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
],
[
'id' => '11', 'message' => 'User 2 Space 2 Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2',
'content' => ['visibility' => '0', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
],
[
'id' => '12', 'message' => 'Admin Space 2 Post Public', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1',
'content' => ['visibility' => '1', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
],
[
'id' => '13', 'message' => 'Admin Space 2 Post Private', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '1',
'content' => ['visibility' => '0', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '1', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '1', 'stream_channel' => 'default'],
],
// Posts to Space 2 of User 2 (Archived)
[
'id' => '14', 'message' => 'User 2 Space 2 Post Archived', 'url' => null, 'created_at' => '2014-08-08 05:36:06', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:06', 'updated_by' => '2',
'content' => ['visibility' => '1', 'archived' => '1', 'contentcontainer_id' => 5, 'created_at' => '2014-08-08 05:36:05', 'created_by' => '2', 'updated_at' => '2014-08-08 05:36:05', 'updated_by' => '2', 'stream_channel' => 'default'],
],
];

View File

@ -0,0 +1,66 @@
<?php
namespace tests\codeception\_support;
use humhub\libs\UUID;
use humhub\modules\content\models\Content;
use yii\test\ActiveFixture;
/**
* Base fixture for ActiveFixtures that represents a `ContentActiveRecord`.
*
* Automatically an corresponding record in the `content` table is created for fixture rows.
* The fixture data can also contain an additional column named `content` with individual content attributes.
* e.g.
*
*```
* return [
* ['id' => '1', 'message' => 'Post 1', 'content' => ['contentcontainer_id' => 1]],
* ['id' => '2', 'message' => 'Post 2', 'content' => ['contentcontainer_id' => 2]]
* ];
* ```
*
* @since 1.12.1
*/
abstract class ContentActiveFixture extends ActiveFixture
{
/**
* @inheritDoc
*/
public function load()
{
$this->data = [];
$table = $this->getTableSchema();
foreach ($this->getData() as $alias => $row) {
$contentRow = (isset($row['content']) && is_array($row['content'])) ? $row['content'] : [];
unset($row['content']);
$primaryKeys = $this->db->schema->insert($table->fullName, $row);
$this->data[$alias] = array_merge($row, $primaryKeys);
// Add Content
$contentRowDefaults = [
'guid' => UUID::v4(),
'object_model' => $this->modelClass,
'object_id' => $primaryKeys['id'],
'visibility' => Content::VISIBILITY_PRIVATE,
'created_by' => 1,
'updated_by' => 1,
'contentcontainer_id' => 1,
'stream_channel' => Content::STREAM_CHANNEL_DEFAULT
];
$this->db->schema->insert('content', array_merge($contentRowDefaults, $contentRow));
}
}
/**
* @inheritDoc
*/
public function unload()
{
$this->db->createCommand()->delete('content', ['object_model' => $this->modelClass])
->execute();
parent::unload();
}
}