/**
  * @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}"));
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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 testFilter()
 {
     $book = new \AuthorBooks\Model\Book();
     $results = array();
     result_ok($results[] = $book->create(array('title' => 'My Book I')));
     result_ok($results[] = $book->create(array('title' => 'My Book II')));
     result_ok($results[] = $book->create(array('title' => 'Perl Programming')));
     result_ok($results[] = $book->create(array('title' => 'My Book IV')));
     $books = new \AuthorBooks\Model\BookCollection();
     $books->fetch();
     count_ok(4, $books);
     $perlBooks = $books->filter(function ($item) {
         return $item->title == 'Perl Programming';
     });
     ok($perlBooks);
     is(1, $perlBooks->size());
     count_ok(1, $perlBooks->items());
     foreach ($results as $result) {
         ok($result->id);
         $record = new Book($result->id);
         $record->delete();
     }
     $someBooks = $books->splice(0, 2);
     is(2, count($someBooks));
 }
Esempio n. 5
0
 public function testLoadOrCreateModel()
 {
     $results = array();
     $b = new \AuthorBooks\Model\Book();
     $ret = $b->create(array('title' => 'Should Create, not load this'));
     $this->assertResultSuccess($ret);
     $results[] = $ret;
     $ret = $b->create(array('title' => 'LoadOrCreateTest'));
     $this->assertResultSuccess($ret);
     $results[] = $ret;
     $id = $b->id;
     $this->assertNotNull($id);
     $ret = $b->loadOrCreate(array('title' => 'LoadOrCreateTest'), 'title');
     $this->assertResultSuccess($ret);
     $this->assertEquals($id, $b->id, 'is the same ID');
     $this->assertEquals(Result::TYPE_LOAD, $ret->type);
     $results[] = $ret;
     $b2 = new Book();
     $ret = $b2->loadOrCreate(array('title' => 'LoadOrCreateTest'), 'title');
     $this->assertResultSuccess($ret);
     $this->assertEquals($id, $b2->id);
     $results[] = $ret;
     $ret = $b2->loadOrCreate(array('title' => 'LoadOrCreateTest2'), 'title');
     $this->assertResultSuccess($ret);
     $this->assertEquals(Result::TYPE_CREATE, $ret->type);
     $this->assertNotEquals($id, $b2->id, 'we should create anther one');
     $results[] = $ret;
     $b3 = new Book();
     $ret = $b3->loadOrCreate(array('title' => 'LoadOrCreateTest3'), 'title');
     $this->assertResultSuccess($ret);
     $this->assertNotEquals($id, $b3->id, 'we should create anther one');
     $results[] = $ret;
     $this->successfulDelete($b3);
     foreach ($results as $r) {
         $book = new Book();
         $book->find(intval($r->id));
         if ($book->id) {
             $book->delete();
         }
     }
 }
 /**
  * @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);
 }
Esempio n. 7
0
 public function testLoadOrCreateModel()
 {
     $results = array();
     $b = new \AuthorBooks\Model\Book();
     $ret = $b->create(array('title' => 'Should Create, not load this'));
     $this->assertResultSuccess($ret);
     $results[] = $ret;
     $ret = $b->create(array('title' => 'LoadOrCreateTest'));
     $this->assertResultSuccess($ret);
     $results[] = $ret;
     $id = $b->id;
     ok($id);
     $ret = $b->loadOrCreate(array('title' => 'LoadOrCreateTest'), 'title');
     $this->assertResultSuccess($ret);
     is($id, $b->id, 'is the same ID');
     $results[] = $ret;
     $b2 = new \AuthorBooks\Model\Book();
     $ret = $b2->loadOrCreate(array('title' => 'LoadOrCreateTest'), 'title');
     $this->assertResultSuccess($ret);
     is($id, $b2->id);
     $results[] = $ret;
     $ret = $b2->loadOrCreate(array('title' => 'LoadOrCreateTest2'), 'title');
     $this->assertResultSuccess($ret);
     ok($id != $b2->id, 'we should create anther one');
     $results[] = $ret;
     $b3 = new \AuthorBooks\Model\Book();
     $ret = $b3->loadOrCreate(array('title' => 'LoadOrCreateTest3'), 'title');
     $this->assertResultSuccess($ret);
     ok($id != $b3->id, 'we should create anther one');
     $results[] = $ret;
     $this->successfulDelete($b3);
     foreach ($results as $r) {
         $book = new Book();
         $book->delete($r->id);
     }
 }