2008-11-11 00:18:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class YamlFixtureTest extends SapphireTest {
|
2011-03-30 08:47:30 +02:00
|
|
|
|
|
|
|
static $fixture_file = 'YamlFixtureTest.yml';
|
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';
|
2011-03-30 08:47:30 +02:00
|
|
|
$obj = new YamlFixture($absPath);
|
|
|
|
$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';
|
2011-03-30 08:47:30 +02:00
|
|
|
$obj = new YamlFixture($relPath);
|
|
|
|
$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);
|
|
|
|
$obj = new YamlFixture($string);
|
|
|
|
$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';
|
2011-03-30 08:47:30 +02:00
|
|
|
$obj = new YamlFixture($invalidPath);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testSQLInsert() {
|
2012-09-26 23:34:00 +02:00
|
|
|
$object1 = DataObject::get_by_id("YamlFixtureTest_DataObject",
|
|
|
|
$this->idFromFixture("YamlFixtureTest_DataObject", "testobject1"));
|
2008-11-11 00:18:31 +01:00
|
|
|
$this->assertTrue($object1->ManyMany()->Count() == 2, "Should be 2 items in this manymany relationship");
|
2012-09-26 23:34:00 +02:00
|
|
|
$object2 = DataObject::get_by_id("YamlFixtureTest_DataObject",
|
|
|
|
$this->idFromFixture("YamlFixtureTest_DataObject", "testobject2"));
|
2008-11-11 00:18:31 +01:00
|
|
|
$this->assertTrue($object2->ManyMany()->Count() == 2, "Should be 2 items in this manymany relationship");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
}
|