Exemplo n.º 1
0
 public function testFetch()
 {
     $role = Roles::fetch(10);
     $this->assertEquals(array('id' => 10, 'name' => 'Some test user'), $role->toArray());
     $this->assertInstanceOf('\\ntentan\\nibii\\RecordWrapper', $role);
     $this->assertTrue(is_numeric($role->toArray()['id']));
     $role = Roles::filterByName('Matches')->fetchFirst();
     $this->assertEquals(array('id' => 11, 'name' => 'Matches'), $role->toArray());
     $role = Roles::filterByName('Matches')->fetch();
     $this->assertEquals(array(array('id' => 11, 'name' => 'Matches')), $role->toArray());
     $role = Roles::filterByName('Matches', 'Rematch')->fetch();
     $this->assertEquals(array(array('id' => 11, 'name' => 'Matches'), array('id' => 12, 'name' => 'Rematch')), $role->toArray());
     $role = Roles::fetchWithName('Matches');
     $this->assertEquals(array(array('id' => 11, 'name' => 'Matches')), $role->toArray());
     $role = Roles::fetchFirstWithName('Matches');
     $this->assertEquals(array('id' => 11, 'name' => 'Matches'), $role->toArray());
     $this->assertEquals(1, count($role));
     $this->assertEquals(11, $role->id);
     $this->assertEquals(11, $role['id']);
     $this->assertArrayHasKey('id', $role);
     $this->assertArrayHasKey('name', $role);
     $this->assertArrayNotHasKey('other', $role);
     $users = Users::fetch();
     //$this->assertEquals(4, count($users));
     $this->assertEquals(1, count($users[0]));
     $users = Users::fields('id', 'username')->filterByUsername('james')->fetchFirst();
     $this->assertEquals(1, count($users));
     $this->assertArrayNotHasKey('firstname', $users);
     $this->assertArrayHasKey('username', $users);
     $this->assertArrayHasKey('id', $users);
 }
Exemplo n.º 2
0
 public function testHasMany()
 {
     $role = \ntentan\nibii\tests\models\raw\Roles::fetch(12);
     $results = array(0 => array('id' => 3, 'username' => 'kwame', 'password' => 'coolthings', 'role_id' => 12, 'firstname' => 'Kwame', 'lastname' => 'Nyarko', 'othernames' => NULL, 'status' => 2, 'email' => '*****@*****.**', 'phone' => NULL, 'office' => NULL, 'last_login_time' => NULL, 'is_admin' => NULL), 1 => array('id' => 4, 'username' => 'adjoa', 'password' => 'hahaha', 'role_id' => 12, 'firstname' => 'Adjoa', 'lastname' => 'Boateng', 'othernames' => NULL, 'status' => 2, 'email' => '*****@*****.**', 'phone' => NULL, 'office' => NULL, 'last_login_time' => NULL, 'is_admin' => NULL));
     $this->assertEquals($results, $role->{'\\ntentan\\nibii\\tests\\models\\raw\\Users'}->toArray());
 }