/** * @covers Veles\Model\User::getGroup */ public function testGetGroup() { $expected = 16; $actual = $this->object->getGroup(); $msg = 'User::getGroup() returns wrong result!'; $this->assertSame($expected, $actual, $msg); $expected = UsrGroup::ADMIN; $db_result = ['id' => 1, 'email' => '*****@*****.**', 'hash' => '$2a$07$usesomesillystringforeGlOaUExBSD9HxuEYk2ZFaeDhggU716O', 'group' => $expected, 'last_login' => 'string']; $adapter = $this->getMockBuilder('\\Veles\\DataBase\\Adapters\\PdoAdapter')->setMethods(['row'])->getMock(); $adapter->expects($this->once())->method('row')->willReturn($db_result); Db::setAdapter($adapter); $this->object->getById(1); $actual = $this->object->getGroup(); $this->assertSame($expected, $actual, $msg); }
/** * User password check in ajax-authentication * * @param User $user User * @param string $password Password retrieved through ajax * @return bool */ public static function check(User $user, $password) { return $user->getHash() === crypt($password, $user->getHash()); }
/** * DataProvider for PasswordTest::testCheckCookieHash */ public function checkCookieHashProvider() { $user = new User(); $user->hash = crypt('password', '$2a$07$' . Helper::genStr() . '$'); return [[$user, $user->getCookieHash(), true], [$user, 'wrongHash', false]]; }
/** * @covers Veles\Model\ActiveRecord::getAll */ public function testGetAll() { $expected = []; for ($i = 1; $i <= 5; ++$i) { $expected[] = ['id' => "{$i}", 'title' => "title_{$i}", 'content' => "content_{$i}", 'author' => "author_{$i}"]; } $adapter = $this->getMockBuilder('\\Veles\\DataBase\\Adapters\\PdoAdapter')->setMethods(['rows', 'getFoundRows'])->getMock(); $adapter->expects($this->at(0))->method('rows')->willReturn($expected); $adapter->expects($this->at(1))->method('rows')->willReturn([]); $adapter->expects($this->once())->method('getFoundRows')->willReturn(5); Db::setAdapter($adapter); $pager = new DbPaginator('paginator_default.phtml'); $news = new News(); $result = $news->getAll(false, $pager); $msg = 'ActiveRecord::getAll() returns wrong result!'; $this->assertSame($expected, $result, $msg); $expected = false; $user = new User(); $result = $user->getAll(); $msg = 'ActiveRecord::getAll() returns wrong result!'; $this->assertSame($expected, $result, $msg); }