2008-11-11 00:18:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class YamlFixtureTest extends SapphireTest {
|
2011-03-30 08:47:30 +02:00
|
|
|
|
2010-04-12 04:03:16 +02:00
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'YamlFixtureTest_DataObject',
|
|
|
|
'YamlFixtureTest_DataObjectRelation',
|
|
|
|
);
|
2008-11-11 00:18:31 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testAbsoluteFixturePath() {
|
2012-03-24 04:38:57 +01:00
|
|
|
$absPath = FRAMEWORK_PATH . '/tests/testing/YamlFixtureTest.yml';
|
2012-12-07 18:44:00 +01:00
|
|
|
$obj = Injector::inst()->create('YamlFixture', $absPath);
|
2011-03-30 08:47:30 +02:00
|
|
|
$this->assertEquals($absPath, $obj->getFixtureFile());
|
2012-06-29 00:33:00 +02:00
|
|
|
$this->assertNull($obj->getFixtureString());
|
2011-03-30 08:47:30 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testRelativeFixturePath() {
|
2012-03-24 04:38:57 +01:00
|
|
|
$relPath = FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml';
|
2012-12-07 18:44:00 +01:00
|
|
|
$obj = Injector::inst()->create('YamlFixture', $relPath);
|
2011-03-30 08:47:30 +02:00
|
|
|
$this->assertEquals(Director::baseFolder() . '/' . $relPath, $obj->getFixtureFile());
|
2012-06-29 00:33:00 +02:00
|
|
|
$this->assertNull($obj->getFixtureString());
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testStringFixture() {
|
2012-06-29 00:33:00 +02:00
|
|
|
$absPath = FRAMEWORK_PATH . '/tests/testing/YamlFixtureTest.yml';
|
|
|
|
$string = file_get_contents($absPath);
|
2012-12-07 18:44:00 +01:00
|
|
|
$obj = Injector::inst()->create('YamlFixture', $string);
|
2012-06-29 00:33:00 +02:00
|
|
|
$this->assertEquals($string, $obj->getFixtureString());
|
|
|
|
$this->assertNull($obj->getFixtureFile());
|
2011-03-30 08:47:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testFailsWithInvalidFixturePath() {
|
2012-03-24 04:38:57 +01:00
|
|
|
$invalidPath = FRAMEWORK_DIR . '/tests/testing/invalid.yml';
|
2012-12-07 18:44:00 +01:00
|
|
|
$obj = Injector::inst()->create('YamlFixture', $invalidPath);
|
2011-03-30 08:47:30 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testSQLInsert() {
|
2013-03-19 12:57:48 +01:00
|
|
|
$factory = new FixtureFactory();
|
2012-12-07 18:44:00 +01:00
|
|
|
$relPath = FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml';
|
|
|
|
$fixture = Injector::inst()->create('YamlFixture', $relPath);
|
2013-03-19 12:57:48 +01:00
|
|
|
$fixture->writeInto($factory);
|
2012-12-07 18:44:00 +01:00
|
|
|
|
2013-03-19 12:57:48 +01:00
|
|
|
$this->assertGreaterThan(0, $factory->getId("YamlFixtureTest_DataObject", "testobject1"));
|
2012-12-07 18:44:00 +01:00
|
|
|
$object1 = DataObject::get_by_id(
|
|
|
|
"YamlFixtureTest_DataObject",
|
2013-03-19 12:57:48 +01:00
|
|
|
$factory->getId("YamlFixtureTest_DataObject", "testobject1")
|
2012-12-07 18:44:00 +01:00
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$object1->ManyMany()->Count() == 2,
|
|
|
|
"Should be two items in this relationship"
|
|
|
|
);
|
2013-03-19 12:57:48 +01:00
|
|
|
$this->assertGreaterThan(0, $factory->getId("YamlFixtureTest_DataObject", "testobject2"));
|
2012-12-07 18:44:00 +01:00
|
|
|
$object2 = DataObject::get_by_id(
|
|
|
|
"YamlFixtureTest_DataObject",
|
2013-03-19 12:57:48 +01:00
|
|
|
$factory->getId("YamlFixtureTest_DataObject", "testobject2")
|
2012-12-07 18:44:00 +01:00
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$object2->ManyMany()->Count() == 1,
|
|
|
|
"Should be one item in this relationship"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWriteInto() {
|
|
|
|
$factory = Injector::inst()->create('FixtureFactory');
|
|
|
|
|
|
|
|
$relPath = FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml';
|
|
|
|
$fixture = Injector::inst()->create('YamlFixture', $relPath);
|
|
|
|
$fixture->writeInto($factory);
|
|
|
|
|
|
|
|
$this->assertGreaterThan(0, $factory->getId("YamlFixtureTest_DataObject", "testobject1"));
|
2008-11-11 00:18:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-12 04:03:16 +02:00
|
|
|
class YamlFixtureTest_DataObject extends DataObject implements TestOnly {
|
2008-11-11 00:18:31 +01:00
|
|
|
static $db = array(
|
|
|
|
"Name" => "Varchar"
|
|
|
|
);
|
|
|
|
static $many_many = array(
|
|
|
|
"ManyMany" => "YamlFixtureTest_DataObjectRelation"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-04-12 04:03:16 +02:00
|
|
|
class YamlFixtureTest_DataObjectRelation extends DataObject implements TestOnly {
|
2008-11-11 00:18:31 +01:00
|
|
|
static $db = array(
|
|
|
|
"Name" => "Varchar"
|
|
|
|
);
|
|
|
|
static $belongs_many_many = array(
|
|
|
|
"TestParent" => "YamlFixtureTest_DataObject"
|
|
|
|
);
|
|
|
|
}
|