silverstripe-framework/tests/testing/YamlFixtureTest.php
Sam Minnee 1f7fc1f76a FIX Remove instances of lines longer than 120c
The entire framework repo (with the exception of system-generated files) has been amended to respect the 120c line-length limit.  This is in preparation for the enforcement of this rule with PHP_CodeSniffer.
2012-09-30 17:18:13 +13:00

69 lines
2.2 KiB
PHP

<?php
class YamlFixtureTest extends SapphireTest {
static $fixture_file = 'YamlFixtureTest.yml';
protected $extraDataObjects = array(
'YamlFixtureTest_DataObject',
'YamlFixtureTest_DataObjectRelation',
);
public function testAbsoluteFixturePath() {
$absPath = FRAMEWORK_PATH . '/tests/testing/YamlFixtureTest.yml';
$obj = new YamlFixture($absPath);
$this->assertEquals($absPath, $obj->getFixtureFile());
$this->assertNull($obj->getFixtureString());
}
public function testRelativeFixturePath() {
$relPath = FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml';
$obj = new YamlFixture($relPath);
$this->assertEquals(Director::baseFolder() . '/' . $relPath, $obj->getFixtureFile());
$this->assertNull($obj->getFixtureString());
}
public function testStringFixture() {
$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());
}
/**
* @expectedException InvalidArgumentException
*/
public function testFailsWithInvalidFixturePath() {
$invalidPath = FRAMEWORK_DIR . '/tests/testing/invalid.yml';
$obj = new YamlFixture($invalidPath);
}
public function testSQLInsert() {
$object1 = DataObject::get_by_id("YamlFixtureTest_DataObject",
$this->idFromFixture("YamlFixtureTest_DataObject", "testobject1"));
$this->assertTrue($object1->ManyMany()->Count() == 2, "Should be 2 items in this manymany relationship");
$object2 = DataObject::get_by_id("YamlFixtureTest_DataObject",
$this->idFromFixture("YamlFixtureTest_DataObject", "testobject2"));
$this->assertTrue($object2->ManyMany()->Count() == 2, "Should be 2 items in this manymany relationship");
}
}
class YamlFixtureTest_DataObject extends DataObject implements TestOnly {
static $db = array(
"Name" => "Varchar"
);
static $many_many = array(
"ManyMany" => "YamlFixtureTest_DataObjectRelation"
);
}
class YamlFixtureTest_DataObjectRelation extends DataObject implements TestOnly {
static $db = array(
"Name" => "Varchar"
);
static $belongs_many_many = array(
"TestParent" => "YamlFixtureTest_DataObject"
);
}