Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require __DIR__ . '/../src/User.php';
- use PHPUnit\DbUnit\TestCaseTrait;
- use PHPUnit\Framework\TestCase;
- class UserTest extends TestCase
- {
- use TestCaseTrait;
- protected $user;
- public static function setUpBeforeClass()
- {
- $conn = new mysqli(
- 'localhost',
- $GLOBALS['DB_USER'],
- $GLOBALS['DB_PASSWORD'],
- $GLOBALS['DB_NAME']
- );
- User::SetConnection($conn);
- }
- public function getConnection()
- {
- $pdo = new PDO($GLOBALS['DB_DSN'],
- $GLOBALS['DB_USER'],
- $GLOBALS['DB_PASSWORD']);
- return $this->createDefaultDBConnection($pdo, $GLOBALS['DB_NAME']);
- }
- public function getDataSet()
- {
- return $this->createMySQLXMLDataSet(__DIR__ . '/file.xml');
- }
- public function testCreateUser()
- {
- $this->assertEquals(2,
- $this->getConnection()->getRowCount('Users'));
- $myUser = User::CreateUser('pawel2@coderslab.pl', 'qweqwe');
- $this->assertEquals(3,
- $this->getConnection()->getRowCount('Users'));
- $this->assertEquals('pawel2@coderslab.pl', $myUser->getEmail());
- $this->assertEquals('', $myUser->getName());
- $this->assertEquals('', $myUser->getInfo());
- $myUser = User::CreateUser('pawel2@coderslab.pl', 'qweqwe');
- $this->assertEquals(null, $myUser);
- }
- public function testAuthenticate()
- {
- $myUser = User::CreateUser('pawel2@coderslab.pl', 'qweqwe');
- $this->assertNull(User::AuthenticateUser("user@gmail.com", "aaaqqq"));
- $this->assertNull(User::AuthenticateUser("pawel2@coderslab.pl", "aaaqqq"));
- $this->assertEquals("pawel2@coderslab.pl",
- $myUser->getEmail());
- }
- public function testDeleteUser()
- {
- $myUser = User::CreateUser('pawel2@coderslab.pl', 'qweqwe');
- $result = User::DeleteUser($myUser, 'wrongPass');
- $this->assertFalse($result);
- $result = User::DeleteUser($myUser, 'qweqwe');
- $this->assertEquals(2,
- $this->getConnection()->getRowCount('Users'));
- $this->assertTrue($result);
- }
- public function testGetUserInfo()
- {
- $this->assertNull(User::GetUserInfo(5));
- $this->assertEquals(['id' => 2,
- 'name' => 'Receiver',
- 'email' => 'receiver@gmail.com',
- 'info' => 'qweqwe'], User::GetUserInfo(2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement