public function testJoin() { $blogDataSource = Mock_Blog::getDataSource(); $entity = $blogDataSource->makeNew(); $entity->set("Title", "This is the first blog"); $entity->set("Description", "and this is the first description"); $blogDataSource->create($entity); $blogCommentDataSource = Mock_BlogComment::getDataSource(); $entity = $blogCommentDataSource->makeNew(); $entity->set("BlogId", 2); $entity->set("Comment", "WTF"); $blogCommentDataSource->create($entity); $entity = $blogCommentDataSource->makeNew(); $entity->set("BlogId", 1); $entity->set("Comment", "Blog Comment"); $blogCommentDataSource->create($entity); $blog = $entity->getRelation("BlogId"); $filter = $blogCommentDataSource->makeFilter(); $filter->addJoin($blogCommentDataSource->getTableName(), "BlogId", $blogDataSource->getTableName(), "Id"); $filter->addConditional($blogDataSource->getTableName(), "Title", "This is the first blog"); $dataset = $blogCommentDataSource->retrieve($filter); $this->assertType("Atrox_Core_Data_Dataset", $dataset); $this->assertType("Mock_BlogComment", $blogCommentRecord = $dataset->getNext()); $this->assertEquals("Blog Comment", $blogCommentRecord->get("Comment")); }
public function testToObject() { $dataSource = Mock_Blog::getDataSource(); $entity = $dataSource->makeNew(); $this->assertEquals("This is the default title", $entity->get("Title")); $response = new stdClass(); $response->id = new stdClass(); $response->id->data = ""; $response->title = new stdClass(); $response->title->data = "This is the default title"; $response->description = new stdClass(); $response->description->data = ""; $response->dateCreated = new stdClass(); $response->dateCreated->data = ""; $this->assertEquals($response, $entity->toObject(false)); $entity->set("Title", " Big Dog "); $response = new stdClass(); $response->id = new stdClass(); $response->id->data = ""; $response->title = new stdClass(); $response->title->data = "Big Dog"; $response->description = new stdClass(); $response->description->data = ""; $response->dateCreated = new stdClass(); $response->dateCreated->data = ""; $this->assertEquals($response, $entity->toObject(false)); $response = new stdClass(); $response->id = new stdClass(); $response->id->data = ""; $response->id->formatted = ""; $response->title = new stdClass(); $response->title->data = "Big Dog"; $response->title->formatted = "Big Dog"; $response->description = new stdClass(); $response->description->data = ""; $response->description->formatted = ""; $response->dateCreated = new stdClass(); $response->dateCreated->data = ""; $response->dateCreated->formatted = "-"; $this->assertEquals($response, $entity->toObject()); $entity->set("DateCreated", "2009-05-01 11:34:00"); $response->dateCreated->data = "2009-05-01 10:34:00"; $response->dateCreated->formatted = "1 May 2009"; $this->assertEquals($response, $entity->toObject()); }
public function testGetPage() { $filter = Mock_Blog::getDataSource()->makeFilter(); $dataSource = Mock_Blog::getDataSource(); $dataset = $dataSource->retrieve($filter); //Getting Page 1 with no records in DB $i = 0; while ($entity = $dataset->getPage(1, 5)) { $i++; } $this->assertEquals(0, $i); //Getting Page 1 with 0 length with no records in DB $i = 0; while ($entity = $dataset->getPage(1, 0)) { $i++; } $this->assertEquals(0, $i); //Add 9 Records. for ($i = 1; $i <= 9; $i++) { $newBlog = $dataSource->makeNew(); $newBlog->set("Title", "{$i}"); $newBlog->set("Description", "Some Description {$i}"); $dataSource->create($newBlog); } $dataset = $dataSource->retrieve($filter); //Getting Page 1 with 0 length with records in DB $i = 0; while ($entity = $dataset->getPage(1, 0)) { $i++; } $this->assertEquals(0, $i); //Getting Page 1 with records in DB $i = 0; while ($entity = $dataset->getPage(1, 5)) { $i++; $this->assertType("Mock_Blog", $entity); $this->assertEquals($i, $entity->getId()); } $this->assertEquals(5, $i); //Getting Page 2 with records in DB $i = 0; while ($entity = $dataset->getPage(2, 5)) { $i++; $this->assertType("Mock_Blog", $entity); $this->assertEquals($i + 5, $entity->getId()); } $this->assertEquals(4, $i); //Getting Page 3 with records in DB should return false immediately $i = 0; while ($entity = $dataset->getPage(3, 5)) { $i++; } $this->assertEquals(0, $i); //Requesting page 1 with a length longer than rows in DB $i = 0; while ($entity = $dataset->getPage(1, 11)) { $i++; $this->assertType("Mock_Blog", $entity); $this->assertEquals($i, $entity->getId()); } $this->assertEquals(9, $i); }
public function testValidate() { $dataSource = Mock_Blog::getDataSource(); $entity = $dataSource->makeNew(); $dataSource->validate($entity); $this->assertEquals(array("'Description' is required"), $this->application->getErrorHandler()->getErrors()); $entity = $dataSource->makeNew(); $entity->set("Title", ""); $entity->set("Description", ""); $dataSource->validate($entity); $this->assertEquals(array("'Title' is required", "'Description' is required"), $this->application->getErrorHandler()->getErrors()); }