|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace OpCacheGUITest\Unit\Auth; |
| 4 | + |
| 5 | +use OpCacheGUI\Auth\User; |
| 6 | + |
| 7 | +class UserTest extends \PHPUnit_Framework_TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @covers OpCacheGUI\Auth\User::__construct |
| 11 | + * @covers OpCacheGUI\Auth\User::isLoggedIn |
| 12 | + */ |
| 13 | + public function testIsloggedInTrue() |
| 14 | + { |
| 15 | + $session = $this->getMock('\\OpCacheGUI\\Storage\\Session'); |
| 16 | + $session->method('isKeyValid')->willReturn(true); |
| 17 | + |
| 18 | + $user = new User($session, 'user', 'pass'); |
| 19 | + |
| 20 | + $this->assertTrue($user->isLoggedIn()); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * @covers OpCacheGUI\Auth\User::__construct |
| 25 | + * @covers OpCacheGUI\Auth\User::isLoggedIn |
| 26 | + */ |
| 27 | + public function testIsloggedInFalse() |
| 28 | + { |
| 29 | + $session = $this->getMock('\\OpCacheGUI\\Storage\\Session'); |
| 30 | + $session->method('isKeyValid')->willReturn(false); |
| 31 | + |
| 32 | + $user = new User($session, 'user', 'pass'); |
| 33 | + |
| 34 | + $this->assertFalse($user->isLoggedIn()); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @covers OpCacheGUI\Auth\User::__construct |
| 39 | + * @covers OpCacheGUI\Auth\User::requiresLogin |
| 40 | + */ |
| 41 | + public function testRequiresLoginLoginNotEnabledInConfig() |
| 42 | + { |
| 43 | + $user = new User($this->getMock('\\OpCacheGUI\\Storage\\Session'), '', ''); |
| 44 | + |
| 45 | + $this->assertFalse($user->requiresLogin()); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @covers OpCacheGUI\Auth\User::__construct |
| 50 | + * @covers OpCacheGUI\Auth\User::isLoggedIn |
| 51 | + * @covers OpCacheGUI\Auth\User::requiresLogin |
| 52 | + */ |
| 53 | + public function testRequiresLoginRequiredButNotLoggedIn() |
| 54 | + { |
| 55 | + $session = $this->getMock('\\OpCacheGUI\\Storage\\Session'); |
| 56 | + $session->method('isKeyValid')->willReturn(false); |
| 57 | + |
| 58 | + $user = new User($session, 'foo', 'bar'); |
| 59 | + |
| 60 | + $this->assertTrue($user->requiresLogin()); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @covers OpCacheGUI\Auth\User::__construct |
| 65 | + * @covers OpCacheGUI\Auth\User::isLoggedIn |
| 66 | + * @covers OpCacheGUI\Auth\User::requiresLogin |
| 67 | + */ |
| 68 | + public function testRequiresLoginRequiredAndLoggedIn() |
| 69 | + { |
| 70 | + $session = $this->getMock('\\OpCacheGUI\\Storage\\Session'); |
| 71 | + $session->method('isKeyValid')->willReturn(true); |
| 72 | + |
| 73 | + $user = new User($session, 'foo', 'bar'); |
| 74 | + |
| 75 | + $this->assertFalse($user->requiresLogin()); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @covers OpCacheGUI\Auth\User::__construct |
| 80 | + * @covers OpCacheGUI\Auth\User::login |
| 81 | + */ |
| 82 | + public function testLoginFailedIncorrectPassword() |
| 83 | + { |
| 84 | + $user = new User($this->getMock('\\OpCacheGUI\\Storage\\Session'), 'foo', 'bar'); |
| 85 | + |
| 86 | + $this->assertFalse($user->login('foo', 'nothashedbar')); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @covers OpCacheGUI\Auth\User::__construct |
| 91 | + * @covers OpCacheGUI\Auth\User::login |
| 92 | + */ |
| 93 | + public function testLoginFailedIncorrectUsername() |
| 94 | + { |
| 95 | + $user = new User($this->getMock('\\OpCacheGUI\\Storage\\Session'), 'foo', 'bar'); |
| 96 | + |
| 97 | + $this->assertFalse($user->login('incorrect', '$2y$14$Gh5y/MR130J3V1xhH5eGWOvpTMgLu9Er82o3ZNrhxMuyZm6Sdx96q')); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @covers OpCacheGUI\Auth\User::__construct |
| 102 | + * @covers OpCacheGUI\Auth\User::login |
| 103 | + */ |
| 104 | + public function testLoginFailedIncorrectPasswordAndUsername() |
| 105 | + { |
| 106 | + $user = new User($this->getMock('\\OpCacheGUI\\Storage\\Session'), 'foo', 'bar'); |
| 107 | + |
| 108 | + $this->assertFalse($user->login('incorrect', 'incorrect')); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * @covers OpCacheGUI\Auth\User::__construct |
| 113 | + * @covers OpCacheGUI\Auth\User::login |
| 114 | + */ |
| 115 | + public function testLoginSuccess() |
| 116 | + { |
| 117 | + $user = new User($this->getMock('\\OpCacheGUI\\Storage\\Session'), 'foo', 'bar'); |
| 118 | + |
| 119 | + $this->assertFalse($user->login('foo', '$2y$14$Gh5y/MR130J3V1xhH5eGWOvpTMgLu9Er82o3ZNrhxMuyZm6Sdx96q')); |
| 120 | + } |
| 121 | +} |
0 commit comments