Пример #1
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);
     }
 }
Пример #2
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();
         }
     }
 }