/**
  * Replaces fixture references in values with their respective database IDs, 
  * with the notation "=><class>.<identifier>". Example: "=>Page.My Page".
  * 
  * @Transform /^([^"]+)$/
  */
 public function lookupFixtureReference($string)
 {
     if (preg_match('/^=>/', $string)) {
         list($className, $identifier) = explode('.', preg_replace('/^=>/', '', $string), 2);
         $id = $this->fixtureFactory->getId($className, $identifier);
         if (!$id) {
             throw new \InvalidArgumentException(sprintf('Cannot resolve reference "%s", no matching fixture found', $string));
         }
         return $id;
     } else {
         return $string;
     }
 }
示例#2
0
 /**
  * Get the ID of an object from the fixture.
  *
  * @deprecated 4.0 Use writeInto() and FixtureFactory accessors instead
  * 
  * @param $className The data class, as specified in your fixture file.  Parent classes won't work
  * @param $identifier The identifier string, as provided in your fixture file
  */
 public function idFromFixture($className, $identifier)
 {
     Deprecation::notice('4.0', 'Use writeInto() and FixtureFactory accessors instead');
     if (!$this->factory) {
         $this->factory = Injector::inst()->create('FixtureFactory');
     }
     return $this->factory->getId($className, $identifier);
 }
 public function testClearWithClass()
 {
     $factory = new FixtureFactory();
     $obj1 = $factory->createObject('FixtureFactoryTest_DataObject', 'object-one');
     $relation1 = $factory->createObject('FixtureFactoryTest_DataObjectRelation', 'relation-one');
     $factory->clear('FixtureFactoryTest_DataObject');
     $this->assertFalse($factory->getId('FixtureFactoryTest_DataObject', 'one'));
     $this->assertNull(FixtureFactoryTest_DataObject::get()->byId($obj1->ID));
     $this->assertEquals($relation1->ID, $factory->getId('FixtureFactoryTest_DataObjectRelation', 'relation-one'));
     $this->assertInstanceOf('FixtureFactoryTest_DataObjectRelation', FixtureFactoryTest_DataObjectRelation::get()->byId($relation1->ID));
 }