public function testOneToManyAssociationWithExtension()
 {
     $contact = new DataExtensionTest_Member();
     $contact->Website = "http://www.example.com";
     $object = new DataExtensionTest_RelatedObject();
     $object->FieldOne = "Lorem ipsum dolor";
     $object->FieldTwo = "Random notes";
     // The following code doesn't currently work:
     // $contact->RelatedObjects()->add($object);
     // $contact->write();
     // Instead we have to do the following
     $contact->write();
     $object->ContactID = $contact->ID;
     $object->write();
     $contactID = $contact->ID;
     unset($contact);
     unset($object);
     $contact = DataObject::get_one("DataExtensionTest_Member", array('"DataExtensionTest_Member"."Website"' => 'http://www.example.com'));
     $object = DataObject::get_one('DataExtensionTest_RelatedObject', array('"DataExtensionTest_RelatedObject"."ContactID"' => $contactID));
     $this->assertNotNull($object, 'Related object not null');
     $this->assertInstanceOf('DataExtensionTest_Member', $object->Contact(), 'Related contact is a member dataobject');
     $this->assertInstanceOf('DataExtensionTest_Member', $object->getComponent('Contact'), 'getComponent does the same thing as Contact()');
     $this->assertInstanceOf('DataExtensionTest_RelatedObject', $contact->RelatedObjects()->First());
     $this->assertEquals("Lorem ipsum dolor", $contact->RelatedObjects()->First()->FieldOne);
     $this->assertEquals("Random notes", $contact->RelatedObjects()->First()->FieldTwo);
     $contact->delete();
 }
Exemplo n.º 2
0
 function testOneToManyAssociationWithExtension()
 {
     // Fails in RestfulServerTest
     // Error: Object::__call() Method 'RelatedObjects' not found in class 'RestfulServerTest_Comment'
     $contact = new DataExtensionTest_Member();
     $contact->Website = "http://www.example.com";
     $object = new DataExtensionTest_RelatedObject();
     $object->FieldOne = "Lorem ipsum dolor";
     $object->FieldTwo = "Random notes";
     // The following code doesn't currently work:
     // $contact->RelatedObjects()->add($object);
     // $contact->write();
     // Instead we have to do the following
     $contact->write();
     $object->ContactID = $contact->ID;
     $object->write();
     $contactID = $contact->ID;
     unset($contact);
     unset($object);
     $contact = DataObject::get_one("DataExtensionTest_Member", "\"Website\"='http://www.example.com'");
     $object = DataObject::get_one('DataExtensionTest_RelatedObject', "\"ContactID\" = {$contactID}");
     $this->assertNotNull($object, 'Related object not null');
     $this->assertType('DataExtensionTest_Member', $object->Contact(), 'Related contact is a member dataobject');
     $this->assertType('DataExtensionTest_Member', $object->getComponent('Contact'), 'getComponent does the same thing as Contact()');
     $this->assertType('DataExtensionTest_RelatedObject', $contact->RelatedObjects()->First());
     $this->assertEquals("Lorem ipsum dolor", $contact->RelatedObjects()->First()->FieldOne);
     $this->assertEquals("Random notes", $contact->RelatedObjects()->First()->FieldTwo);
     $contact->delete();
 }