function testTwoSubclassesWithTheSameFieldNameWork()
 {
     // Create two objects of different subclasses, setting the values of fields that are
     // defined separately in each subclass
     $obj1 = new DataObjectTest_SubTeam();
     $obj1->SubclassDatabaseField = "obj1";
     $obj2 = new OtherSubclassWithSameField();
     $obj2->SubclassDatabaseField = "obj2";
     // Write them to the database
     $obj1->write();
     $obj2->write();
     // Check that the values of those fields are properly read from the database
     $values = DataObject::get("DataObjectTest_Team", "\"DataObjectTest_Team\".\"ID\" IN \n\t\t\t({$obj1->ID}, {$obj2->ID})")->column("SubclassDatabaseField");
     $this->assertEquals(array('obj1', 'obj2'), $values);
 }
	public function testForceInsert() {	
		/* If you set an ID on an object and pass forceInsert = true, then the object should be correctly created */
		$obj = new DataObjectTest_SubTeam();
		$obj->ID = 1001;
		$obj->Title = 'asdfasdf';
		$obj->SubclassDatabaseField = 'asdfasdf';
		$obj->write(false, true);

		$this->assertEquals("DataObjectTest_SubTeam", DB::query("SELECT ClassName FROM DataObjectTest_Team WHERE ID = $obj->ID")->value());

		/* Check that it actually saves to the database with the correct ID */
		$this->assertEquals("1001", DB::query("SELECT ID FROM DataObjectTest_SubTeam WHERE SubclassDatabaseField = 'asdfasdf'")->value());
		$this->assertEquals("1001", DB::query("SELECT ID FROM DataObjectTest_Team WHERE Title = 'asdfasdf'")->value());
	}
Esempio n. 3
0
 public function testFilterAndExcludeById()
 {
     $id = $this->idFromFixture('DataObjectTest_SubTeam', 'subteam1');
     $list = DataObjectTest_SubTeam::get()->filter('ID', $id);
     $this->assertEquals($id, $list->first()->ID);
     $list = DataObjectTest_SubTeam::get();
     $this->assertEquals(3, count($list));
     $this->assertEquals(2, count($list->exclude('ID', $id)));
     // Check that classes with namespaces work.
     $obj = new DataObjectTest\NamespacedClass();
     $obj->Name = "Test";
     $obj->write();
     $list = DataObjectTest\NamespacedClass::get()->filter('ID', $obj->ID);
     $this->assertEquals('Test', $list->First()->Name);
     $this->assertEquals(0, $list->exclude('ID', $obj->ID)->count());
 }
Esempio n. 4
0
 /**
  * Test DataList->canSortBy()
  */
 function testCanSortBy()
 {
     // Basic check
     $team = DataObjectTest_Team::get();
     $this->assertTrue($team->canSortBy("Title"));
     $this->assertFalse($team->canSortBy("SomethingElse"));
     // Subclasses
     $subteam = DataObjectTest_SubTeam::get();
     $this->assertTrue($subteam->canSortBy("Title"));
     $this->assertTrue($subteam->canSortBy("SubclassDatabaseField"));
 }