ElementFixture

Type
Abstract Class
Namespace
craft\test\fixtures\elements
Inherits
craft\test\fixtures\elements\ElementFixture » yii\test\ActiveFixture » yii\test\BaseActiveFixture » yii\test\DbFixture » yii\test\Fixture » yii\base\Component » yii\base\BaseObject
Implements
ArrayAccess, Countable, IteratorAggregate, yii\base\Configurable
Uses traits
yii\base\ArrayAccessTrait, yii\test\FileFixtureTrait
Extended by
craft\test\fixtures\elements\AssetFixture, craft\test\fixtures\elements\CategoryFixture, craft\test\fixtures\elements\EntryFixture, craft\test\fixtures\elements\GlobalSetFixture, craft\test\fixtures\elements\TagFixture, craft\test\fixtures\elements\UserFixture
Since
3.2

Class ElementFixture is a base class for setting up fixtures for Craft 3's element types.

Credit to: https://github.com/robuust/craft-fixtures

View source

# Public Properties

Property Description
behaviors yii\base\Behavior – List of behaviors attached to this component
data array – The data rows.
dataDirectory string – The directory path or path alias that contains the fixture data
dataFile string, boolean – The file path or path alias of the data file that contains the fixture data to be returned by \yii\test\getData().
db yii\db\Connection, array, string – The DB connection object or the application component ID of the DB connection.
depends array – The fixtures that this fixture depends on.
element craft\base\ElementInterface, null
iterator ArrayIterator – An iterator for traversing the cookies in the collection.
modelClass string – The AR model class associated with this fixture.
tableName string – The name of the database table that this fixture is about.
tableSchema yii\db\TableSchema – The schema information of the database table associated with this fixture.
unload boolean – Whether the fixture data should be unloaded

# element

Type
craft\base\ElementInterface, null
Access
Read-only

View source

# unload

Type
boolean
Since
3.3.5

Whether the fixture data should be unloaded

View source

# Protected Properties

Property Description
siteIds array

# siteIds

Type
array

View source

# Public Methods

Method Description
__call() Calls the named method which is not a class method.
__clone() This method is called after the object is created by cloning an existing one.
__construct() Constructor.
__get() Returns the value of an object property.
__isset() Checks if a property is set, i.e. defined and not null.
__set() Sets value of an object property.
__unset() Sets an object property to null.
afterLoad() This method is called AFTER all fixture data have been loaded for the current test.
afterUnload() This method is called AFTER all fixture data have been unloaded for the current test.
attachBehavior() Attaches a behavior to this component.
attachBehaviors() Attaches a list of behaviors to the component.
beforeLoad() This method is called BEFORE any fixture data is loaded for the current test.
beforeUnload() This method is called BEFORE any fixture data is unloaded for the current test.
behaviors() Returns a list of behaviors that this component should behave as.
canGetProperty() Returns a value indicating whether a property can be read.
canSetProperty() Returns a value indicating whether a property can be set.
className() Returns the fully qualified name of this class.
count() Returns the number of data items.
detachBehavior() Detaches a behavior from the component.
detachBehaviors() Detaches all behaviors from the component.
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component.
generateElementQuery()
getBehavior() Returns the named behavior object.
getBehaviors() Returns all behaviors attached to this component.
getElement() Get element model.
getIterator() Returns an iterator for traversing the data.
getModel() Returns the AR model by the specified model name.
getTableSchema()
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event.
hasMethod() Returns a value indicating whether a method is defined.
hasProperty() Returns a value indicating whether a property is defined.
init() Initializes the object.
load() Loads the fixture.
off() Detaches an existing event handler from this component.
offsetExists() This method is required by the interface ArrayAccess.
offsetGet() This method is required by the interface ArrayAccess.
offsetSet() This method is required by the interface ArrayAccess.
offsetUnset() This method is required by the interface ArrayAccess.
on() Attaches an event handler to an event.
trigger() Triggers an event.
unload() Unloads the fixture.

# generateElementQuery()

View source

Arguments

Returns

craft\elements\db\ElementQuery

# getElement()

Get element model.

View source

Arguments

  • $data (array, null) – The data to get the element by

Returns

craft\base\ElementInterface, null

# getModel()

Returns the AR model by the specified model name.

A model name is the key of the corresponding data row in data.

View source

Arguments

  • $name (string) – The model name.

Returns

null, yii\db\ActiveRecord – The AR model, or null if the model cannot be found in the database

Throws

# init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

View source

# load()

Loads the fixture.

It populate the table with the data returned by getData().

If you override this method, you should consider calling the parent implementation so that the data returned by getData() can be populated into the table.

View source

# unload()

Unloads the fixture.

This method is called after every test method finishes. You may override this method to perform necessary cleanup work for the fixture.

View source

Throws

# Protected Methods

Method Description
getData() Returns the fixture data.
isPrimaryKey() See if an element's handle is a primary key.
loadData() Returns the fixture data.
resetTable() Removes all existing data from the specified table and resets sequence number to 1 (if any).

# isPrimaryKey()

See if an element's handle is a primary key.

View source

Arguments

Returns

boolean