I was trying to access data from a Matrix field (created in a fixture) in a test, but the data was coming back empty.
<?php
namespace clienttests\fixtures;
use craft\test\fixtures\elements\EntryFixture;
class EntriesFixture extends EntryFixture
{
/**
* @inheritdoc
*/
public $dataFile = __DIR__ . '/data/entries.php';
}
<?php
$productTypeSettingsSection = Craft::$app->sections->getSectionByHandle('productTypeSettings');
return [
[
'authorId' => '1',
'sectionId' => $productTypeSettingsSection->id,
'typeId' => $productTypeSettingsSection->entryTypes[0]->id,
'productType' => 'compressionSprings',
'expandedRowTable' => [
'new1' => [
'type' => 'group',
'enabled' => 1,
'fields' => [
'group' => 'Heading 1',
],
],
'new2' => [
'type' => 'column',
'enabled' => 1,
'fields' => [
'blockAttribute' => 'material',
],
],
],
],
];
<?php
namespace clienttests\unit;
use Codeception\Test\Unit;
use UnitTester;
use Craft;
use clienttests\fixtures\EntriesFixture;
class AlgoliaTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;
public function _fixtures(): array
{
return [
'entries' => [
'class' => EntriesFixture::class,
],
];
}
public function testFormatExpandedRowSettings()
{
$entry = \craft\elements\Entry::findOne([
'section' => 'productTypeSettings',
'with' => [
'expandedRowTable',
],
]);
codecept_debug($entry->expandedRowTable);
}
}
The entry definitely exists, but the contents of the Matrix field is empty.
| Asset Rev | 6.0.2 |
|---|---|
| Classnames | 1.0.2 |
| Command Palette | 3.1.4 |
| Craft Commerce | 3.2.14.1 |
| Feed Me | 4.3.4 |
| Linkit | 1.1.12.1 |
| Ray | 1.0.1 |
| Redactor | 2.8.5 |
| Scout | 2.3.1 |
I think this is actually moot. I looked at the fixtures y'all had in the repo and noticed that the custom fields are now prefixed with field:
Is there already a pending update of the docs? Otherwise I'm happy to open a PR. Thanks!
I鈥檓 on the case, @davist11. Thanks for pointing this out!
Lemme know if that fixed it for you @davist11 and I'll close this one out, otherwise can dig in more.
馃檹
Yep it sure did, thanks.