/** * @rebuild true * @group profile */ public function testProfileCreate() { $b = new Book(); for ($i = 0; $i < $this->N; $i++) { $b->create(array('title' => "OOP Programming Guide: {$i}", 'subtitle' => 'subtitle', 'isbn' => "123123123{$i}")); } }
public function testRecursiveExporting() { $author = new Author(); $ret = $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z')); $this->assertResultSuccess($ret); // Has Many Relationship $author->addresses->create(['address' => 'far far away']); $author->addresses->create(['address' => 'taipei 101']); $author->addresses->create(['address' => 'brazil']); $author->addresses->create(['address' => 'san francisco']); $book = new Book(); $ret = $book->create(['title' => 'Run & Skate']); $this->assertResultSuccess($ret); // ManyToMany $author->author_books->create(['book_id' => $book->id]); $book = new Book(); $ret = $book->create(['title' => 'Run & Skate II']); $this->assertResultSuccess($ret); $author->author_books->create(['book_id' => $book->id]); $exporter = new XMLExporter(); $dom = $exporter->exportRecord($author); $dom->formatOutput = true; $this->assertInstanceOf('DOMDocument', $dom); $xml = $dom->saveXML(); $this->assertNotEmpty($xml); // echo $xml; }
public function testRecursiveExporting() { $author = new Author(); $ret = $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z', 'updated_on' => '2012-01-01 00:00:00', 'created_on' => '2012-01-01 00:00:00')); $this->assertResultSuccess($ret); // Has Many Relationship $author->addresses->create(['address' => 'far far away']); $author->addresses->create(['address' => 'taipei 101']); $author->addresses->create(['address' => 'brazil']); $author->addresses->create(['address' => 'san francisco']); $book = new Book(); $ret = $book->create(['title' => 'Run & Skate', 'published_at' => '2012-01-01 00:00:00', 'updated_on' => '2012-01-01 00:00:00', 'created_on' => '2012-01-01 00:00:00', 'is_selled' => false]); $this->assertResultSuccess($ret); // ManyToMany $author->author_books->create(['book_id' => $book->id, 'created_on' => '2012-01-01 00:00:00']); $book = new Book(); $ret = $book->create(['title' => 'Run & Skate II', 'updated_on' => '2012-01-01 00:00:00', 'created_on' => '2012-01-01 00:00:00', 'published_at' => '2012-01-01 00:00:00', 'is_selled' => false]); $this->assertResultSuccess($ret); $author->author_books->create(['book_id' => $book->id, 'created_on' => '2012-01-01 00:00:00']); $exporter = new XMLExporter(); $dom = $exporter->exportRecord($author); $dom->formatOutput = true; $this->assertInstanceOf('DOMDocument', $dom); $xml = $dom->saveXML(); $this->assertNotEmpty($xml); file_put_contents('tests/xmlTestRecursiveExporting.actual', $xml); $this->assertFileEquals('tests/xmlTestRecursiveExporting.expected', 'tests/xmlTestRecursiveExporting.actual'); }
public function testFind() { $results = array(); $book1 = new Book(); $ret = $book1->create(array('title' => 'Book1')); $this->assertResultSuccess($ret); $book2 = new Book(); $ret = $book2->create(array('title' => 'Book2')); $this->assertResultSuccess($ret); $findBook = new Book(); $ret = $findBook->find($book1->id); $this->assertResultSuccess($ret); $this->assertEquals($book1->id, $findBook->id); $ret = $findBook->find($book2->id); $this->assertResultSuccess($ret); $this->assertEquals($book2->id, $findBook->id); }
/** * @rebuild false */ public function testZeroInflator() { $b = new Book(); $ret = $b->create(array('title' => 'Create X', 'view' => 0)); $this->assertResultSuccess($ret); ok($b->id); is(0, $b->view); $ret = $b->load($ret->id); $this->assertResultSuccess($ret); ok($b->id); is(0, $b->view); // test incremental $ret = $b->update(array('view' => new Raw('view + 1')), array('reload' => true)); $this->assertResultSuccess($ret); is(1, $b->view); $ret = $b->update(array('view' => new Raw('view + 1')), array('reload' => true)); $this->assertResultSuccess($ret); is(2, $b->view); $ret = $b->delete(); $this->assertResultSuccess($ret); }