Example #1
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;
 }
Example #2
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');
 }
 /**
  * @basedata false
  */
 public function testHasManyRelationCreate()
 {
     $author = new Author();
     $ret = $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     $this->assertResultSuccess($ret);
     ok($author->id);
     $address = $author->addresses->create(array('address' => 'farfaraway'));
     ok($address->id);
     ok($address->author_id);
     $this->assertEquals($author->id, $address->author_id);
     $this->assertEquals('farfaraway', $address->address);
     $this->assertResultSuccess($address->delete());
     $this->assertResultSuccess($author->delete());
 }
 public function testCollectionPagerAndSelection()
 {
     $author = new Author();
     foreach (range(1, 10) as $i) {
         $ret = $author->create(array('name' => 'Foo-' . $i, 'email' => 'foo@foo' . $i, 'identity' => 'foo' . $i, 'confirmed' => true));
         ok($author->confirmed, 'is true');
         ok($ret->success);
     }
     $authors = new AuthorCollection();
     $authors->where()->equal('confirmed', true);
     foreach ($authors as $author) {
         ok($author->confirmed);
     }
     is(10, $authors->size());
     /* page 1, 10 per page */
     $pager = $authors->pager(1, 10);
     ok($pager);
     $pager = $authors->pager();
     ok($pager);
     ok($pager->items());
     $array = $authors->toArray();
     ok($array[0]);
     ok($array[9]);
     ok($authors->items());
     is(10, count($authors->items()));
     foreach ($authors as $a) {
         $ret = $a->delete();
         ok($ret->success);
     }
 }
 public function testManyToManyRelationFetch()
 {
     $author = new Author();
     $author->create(array('name' => 'Z', 'email' => 'z@z', 'identity' => 'z'));
     // XXX: in different database engine, it's different.
     // sometimes it's string, sometimes it's integer
     // ok( is_string( $author->getValue('id') ) );
     ok(is_integer($author->get('id')));
     $book = $author->books->create(array('title' => 'Book Test'));
     ok($book);
     ok($book->id, 'book is created');
     $ret = $book->delete();
     ok($ret->success);
     $ab = new \AuthorBooks\Model\AuthorBook();
     $book = new \AuthorBooks\Model\Book();
     // should not include this
     ok($book->create(array('title' => 'Book I Ex'))->success);
     ok($book->create(array('title' => 'Book I'))->success);
     ok($ab->create(array('author_id' => $author->id, 'book_id' => $book->id))->success);
     ok($book->create(array('title' => 'Book II'))->success);
     $ab->create(array('author_id' => $author->id, 'book_id' => $book->id));
     ok($book->create(array('title' => 'Book III'))->success);
     $ab->create(array('author_id' => $author->id, 'book_id' => $book->id));
     // retrieve books from relationshipt
     $author->flushCache();
     $books = $author->books;
     is(3, $books->size(), 'We have 3 books');
     $bookTitles = array();
     foreach ($books->items() as $item) {
         $bookTitles[$item->title] = true;
         $item->delete();
     }
     count_ok(3, array_keys($bookTitles));
     ok($bookTitles['Book I']);
     ok($bookTitles['Book II']);
     ok($bookTitles['Book III']);
     ok(!isset($bookTitles['Book I Ex']));
     $author->delete();
 }
Example #6
0
 public function testUpdateNull()
 {
     $author = new Author();
     $ret = $author->create(array('name' => 'Mary III', 'email' => 'zz3@zz3', 'identity' => 'zz3'));
     $this->assertResultSuccess($ret);
     $id = $author->id;
     $this->assertResultSuccess($author->update(array('name' => 'I')));
     is($id, $author->id);
     is('I', $author->name);
     $this->assertResultSuccess($author->update(array('name' => null)));
     is($id, $author->id);
     is(null, $author->name);
     $this->assertResultSuccess($author->load($author->id));
     is($id, $author->id);
     $this->assertNull($author->name);
 }
Example #7
0
 public function testMigrationRename()
 {
     if ($this->queryDriver instanceof SQLiteDriver) {
         return $this->markTestSkipped('skip this test when sqlite driver is used.');
     }
     $migration = new Migration($this->conn, $this->queryDriver, $this->logger);
     $author = new Author();
     $schema = $author->getDeclareSchema();
     $column = $schema->getColumn('name');
     $newColumn = clone $column;
     $newColumn->name('name2');
     $migration->renameColumn('authors', $column, $newColumn);
     $migration->renameColumn('authors', $newColumn, $column);
 }