Skip to content

Commit

Permalink
GlobalSet Element Fixture improvements
Browse files Browse the repository at this point in the history
Adds ability to specify whether to use AR or Element
  • Loading branch information
boboldehampsink committed Sep 17, 2019
1 parent df7c7e9 commit 99e7a4b
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions src/test/fixtures/elements/GlobalSetFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,56 @@ abstract class GlobalSetFixture extends ElementFixture
*/
public $tableName = Table::GLOBALSETS;

/**
* @var boolean
*/
public $useActiveRecord = true;

/**
* @inheritdoc
*/
public function load()
{
parent::load();

// TODO: layouts?
foreach ($this->data as $alias => $data) {
$record = new GlobalSetRecord();
$record->id = $data['id'];
$record->name = $data['name'];
$record->handle = $data['handle'];
$record->uid = $data['uid'];
$record->save();
if ($this->useActiveRecord) {
parent::load();

// TODO: layouts?
foreach ($this->data as $alias => $data) {
$record = new GlobalSetRecord();
$record->id = $data['id'];
$record->name = $data['name'];
$record->handle = $data['handle'];
$record->uid = $data['uid'];
$record->save();
}

return;
}

$this->data = [];
foreach ($this->getData() as $alias => $data) {
// Pass in $data so we get an existing element
$element = $this->getElement($data);

foreach ($data as $handle => $value) {
$element->$handle = $value;
}

if (!$this->saveElement($element)) {
$this->getErrors($element);
}

$this->data[$alias] = array_merge($data, ['id' => $element->id]);
}
}

/**
* {@inheritdoc}
*/
public function unload(): void
{
if ($this->useActiveRecord) {
parent::unload();
}
}

Expand Down

0 comments on commit 99e7a4b

Please sign in to comment.