1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Azine\HybridAuthBundle\Tests\Services; |
4
|
|
|
|
5
|
|
|
use Azine\HybridAuthBundle\Entity\HybridAuthSessionData; |
6
|
|
|
use Azine\HybridAuthBundle\Services\AzineHybridAuth; |
7
|
|
|
use Azine\HybridAuthBundle\Tests\AzineTestCase; |
8
|
|
|
|
9
|
|
|
class AzineHybridAuthTest extends AzineTestCase |
10
|
|
|
{ |
11
|
|
|
private $azineHybridAuth; |
12
|
|
|
|
13
|
|
|
protected function setUp() |
14
|
|
|
{ |
15
|
|
|
$router = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\Router') |
16
|
|
|
->disableOriginalConstructor() |
17
|
|
|
->getMock(); |
18
|
|
|
|
19
|
|
|
$entityManager = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') |
20
|
|
|
->disableOriginalConstructor() |
21
|
|
|
->getMock(); |
22
|
|
|
|
23
|
|
|
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken') |
28
|
|
|
->disableOriginalConstructor() |
29
|
|
|
->getMock(); |
30
|
|
|
|
31
|
|
|
$tokenStorage->expects($this->any()) |
32
|
|
|
->method('getToken') |
33
|
|
|
->will($this->returnValue($token)); |
34
|
|
|
|
35
|
|
|
$config = array('endpoint_route' => 'route', 'providers' => 'providers', 'debug_mode' => 'debug_mode', 'debug_file' => 'debug_file'); |
36
|
|
|
$this->azineHybridAuth = new AzineHybridAuth($router, $tokenStorage, $entityManager, |
37
|
|
|
$config, false, true, 55); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function testIsExpiredSession() |
41
|
|
|
{ |
42
|
|
|
$sessionData = new HybridAuthSessionData(); |
43
|
|
|
$sessionData->setUsername('dominik'); |
44
|
|
|
|
45
|
|
|
$expirationDate = new \DateTime(); |
46
|
|
|
$expirationDate->modify('- 1 day'); |
47
|
|
|
|
48
|
|
|
$sessionData->setExpiresAt($expirationDate); |
49
|
|
|
$isExpired = $this->azineHybridAuth->isExpiredSession($sessionData); |
50
|
|
|
|
51
|
|
|
$this->assertTrue($isExpired); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function testIsNotExpiredSession() |
55
|
|
|
{ |
56
|
|
|
$sessionData = new HybridAuthSessionData(); |
57
|
|
|
$sessionData->setUsername('dominik'); |
58
|
|
|
|
59
|
|
|
$expirationDate = new \DateTime(); |
60
|
|
|
$expirationDate->modify('+ 1 day'); |
61
|
|
|
|
62
|
|
|
$sessionData->setExpiresAt($expirationDate); |
63
|
|
|
$isExpired = $this->azineHybridAuth->isExpiredSession($sessionData); |
64
|
|
|
|
65
|
|
|
$this->assertFalse($isExpired); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|