BaseContentFixture ​
- Type
- Abstract Class
- Namespace
- craft\test\fixtures\elements
- Inherits
- craft\test\fixtures\elements\BaseContentFixture » yii\test\DbFixture » yii\test\Fixture » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Uses traits
- yii\test\FileFixtureTrait
- Since
- 3.6.0
BaseContentFixture is a base class for setting up fixtures for populating existing elements.
Fixture classes that extend this class should set elementType to the class name of an element type, and dataFile to the path to a data file.
The data file should return an array, where each item is a sub-array containing the following keys:
criteria
– an array of element query param names/values that should be used to locate the elementattributes
– an array of attribute names/values that should be set on the elementfields
– an array of custom field handles/values that should be set on the element
Public Properties ​
Property | Description |
---|---|
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
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. |
elementType | string – The element type this is for |
skipMissingElements | boolean – Whether to skip elements that can’t be found per the criteria in the data file. |
elementType
​
- Type
- string
- Default value
null
The element type this is for
skipMissingElements
​
- Type
- boolean
- Default value
true
Whether to skip elements that can’t be found per the criteria in the data file.
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 a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be 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. |
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. |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getElement() | Get element model. |
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 for this component. |
init() | Initializes the object. |
load() | Loads the fixture. |
off() | Detaches an existing event handler from this component. |
on() | Attaches an event handler to an event. |
trigger() | Triggers an event. |
unload() | Unloads the fixture. |
getElement()
​
Get element model.
Arguments ​
Returns ​
craft\base\ElementInterface, null
init()
​
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
load()
​
Loads the fixture.
This method is called before performing every test method. You should override this method with concrete implementation about how to set up the fixture.
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.
Protected Methods ​
Method | Description |
---|---|
findElement() | Finds an element with the given criteria. |
loadData() | Returns the fixture data. |
populateElement() | Populates an element with the given attributes/custom field values. |
saveElement() | Saves an element. |
findElement()
​
Finds an element with the given criteria.
Arguments ​
$data
(array)
Returns ​
craft\base\ElementInterface, null
populateElement()
​
Populates an element with the given attributes/custom field values.
Arguments ​
$element
(craft\base\ElementInterface)$data
(array)
saveElement()
​
Saves an element.
Arguments ​
$element
(craft\base\ElementInterface) – The element to be saved
Returns ​
boolean – Whether the save was successful