Advertisement
sanjiisan

Untitled

Sep 7th, 2017
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. <?php
  2.  
  3. require __DIR__ . '/../src/User.php';
  4.  
  5. use PHPUnit\DbUnit\TestCaseTrait;
  6. use PHPUnit\Framework\TestCase;
  7.  
  8. class UserTest extends TestCase
  9. {
  10. use TestCaseTrait;
  11. protected $user;
  12.  
  13. public static function setUpBeforeClass()
  14. {
  15. $conn = new mysqli(
  16. 'localhost',
  17. $GLOBALS['DB_USER'],
  18. $GLOBALS['DB_PASSWORD'],
  19. $GLOBALS['DB_NAME']
  20. );
  21.  
  22. User::SetConnection($conn);
  23. }
  24.  
  25. public function getConnection()
  26. {
  27. $pdo = new PDO($GLOBALS['DB_DSN'],
  28. $GLOBALS['DB_USER'],
  29. $GLOBALS['DB_PASSWORD']);
  30.  
  31. return $this->createDefaultDBConnection($pdo, $GLOBALS['DB_NAME']);
  32. }
  33.  
  34. public function getDataSet()
  35. {
  36. return $this->createMySQLXMLDataSet(__DIR__ . '/file.xml');
  37. }
  38.  
  39. public function testCreateUser()
  40. {
  41. $this->assertEquals(2,
  42. $this->getConnection()->getRowCount('Users'));
  43.  
  44. $myUser = User::CreateUser('pawel2@coderslab.pl', 'qweqwe');
  45.  
  46. $this->assertEquals(3,
  47. $this->getConnection()->getRowCount('Users'));
  48.  
  49. $this->assertEquals('pawel2@coderslab.pl', $myUser->getEmail());
  50. $this->assertEquals('', $myUser->getName());
  51. $this->assertEquals('', $myUser->getInfo());
  52.  
  53. $myUser = User::CreateUser('pawel2@coderslab.pl', 'qweqwe');
  54.  
  55. $this->assertEquals(null, $myUser);
  56. }
  57.  
  58. public function testAuthenticate()
  59. {
  60. $myUser = User::CreateUser('pawel2@coderslab.pl', 'qweqwe');
  61. $this->assertNull(User::AuthenticateUser("user@gmail.com", "aaaqqq"));
  62. $this->assertNull(User::AuthenticateUser("pawel2@coderslab.pl", "aaaqqq"));
  63. $this->assertEquals("pawel2@coderslab.pl",
  64. $myUser->getEmail());
  65. }
  66.  
  67. public function testDeleteUser()
  68. {
  69. $myUser = User::CreateUser('pawel2@coderslab.pl', 'qweqwe');
  70.  
  71. $result = User::DeleteUser($myUser, 'wrongPass');
  72. $this->assertFalse($result);
  73. $result = User::DeleteUser($myUser, 'qweqwe');
  74. $this->assertEquals(2,
  75. $this->getConnection()->getRowCount('Users'));
  76. $this->assertTrue($result);
  77.  
  78. }
  79.  
  80. public function testGetUserInfo()
  81. {
  82. $this->assertNull(User::GetUserInfo(5));
  83.  
  84. $this->assertEquals(['id' => 2,
  85. 'name' => 'Receiver',
  86. 'email' => 'receiver@gmail.com',
  87. 'info' => 'qweqwe'], User::GetUserInfo(2));
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement