1

I can't for the life of me figure out how to setup EntryFixtures in craft to populate with custom fields. I'm using the project config which already has the sections and fields defined in my tests. I'm trying to set a field, gmbId, that's set on a locations entry type. Here's my code. I feel like I'm missing something basic here.

codeception.yml

actor: Tester
paths:
  tests: tests
  log: tests/_output
  data: tests/_data
  support: tests/_support
  envs: tests/_envs
bootstrap: _bootstrap.php
params:
  - tests/.env
modules:
  config:
    \craft\test\Craft:
      configFile: "tests/_craft/config/test.php"
      entryUrl: "http://host.docker.internal/index.php"
      projectConfig: {
        folder: "config/project",
        reset: true
      }
      migrations: []
      plugins: []
      cleanup: true
      transaction: true
      dbSetup: { clean: true, setupCraft: true }

LocationFixture.php

<?php

namespace tests\fixtures;

use craft\test\fixtures\elements\EntryFixture;

class LocationFixture extends EntryFixture
{
    public $dataFile = __DIR__ . '/data/locations.php';
}

locations.php

<?php

return [
    [
        'sectionId' => $this->sectionIds['locations'],
        'typeId' => $this->typeIds['locations']['locations'],
        'title' => 'Location 1',
        'gmbId' => '123' # this is the custom field I'm trying to set.
    ],
    [
        'sectionId' => $this->sectionIds['locations'],
        'typeId' => $this->typeIds['locations']['locations'],
        'title' => 'Location 2',
        'gmbId' => '123'
    ],
    [
        'sectionId' => $this->sectionIds['locations'],
        'typeId' => $this->typeIds['locations']['locations'],
        'title' => 'Location 3',
        'gmbId' => '123'
    ]
];

1

Prepending the field name with field: should do the trick.

<?php

return [
    [
        'sectionId' => $this->sectionIds['locations'],
        'typeId' => $this->typeIds['locations']['locations'],
        'title' => 'Location 1',
        'field:gmbId' => '123',
    ],
];

See https://github.com/craftcms/cms/blob/develop/tests/fixtures/data/entry-with-fields.php for reference.

1
  • I'm an idot....this whole time that field wasn't even attached to this particular entrytype. Thank you so much for helping! Feb 17 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.