silverstripe-framework/src/Dev/BehatFixtureFactory.php

29 lines
813 B
PHP
Raw Normal View History

<?php
namespace SilverStripe\Dev;
2017-01-20 03:57:50 +01:00
use SilverStripe\Assets\File;
2016-11-29 00:31:16 +01:00
class BehatFixtureFactory extends FixtureFactory
{
public function createObject($name, $identifier, $data = null)
{
if (!$data) {
$data = array();
}
2016-11-29 00:31:16 +01:00
// Copy identifier to some visible property unless its already defined.
// Exclude files, since they generate their own named based on the file path.
2017-01-20 03:57:50 +01:00
if (!is_a($name, File::class, true)) {
2016-11-29 00:31:16 +01:00
foreach (array('Name', 'Title') as $fieldName) {
if (singleton($name)->hasField($fieldName) && !isset($data[$fieldName])) {
$data[$fieldName] = $identifier;
break;
}
}
}
2016-11-29 00:31:16 +01:00
return parent::createObject($name, $identifier, $data);
}
2013-08-21 11:27:16 +02:00
}