1 | <?php |
||
14 | class Form extends atoum |
||
15 | { |
||
16 | /** |
||
17 | * @var $class : Instance de la class Form |
||
18 | */ |
||
19 | protected $class; |
||
20 | |||
21 | /** |
||
22 | * @var $mock : Instance du mock pour la class Form |
||
23 | */ |
||
24 | protected $mock; |
||
25 | |||
26 | /** |
||
27 | * Instanciation de la class avant chaque méthode de test |
||
28 | */ |
||
29 | public function beforeTestMethod($testMethod) |
||
30 | { |
||
31 | //$this->class = new \BFW\Form(); |
||
32 | $this->mock = new MockForm(); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Test du constructeur : Form($idForm=) |
||
37 | */ |
||
38 | public function testForm() |
||
39 | { |
||
40 | $this->mock = new MockForm(); |
||
41 | $this->variable($this->mock->idForm)->isNull(); |
||
42 | $this->object($this->mock->_kernel)->isInstanceOf('\BFW\Kernel'); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Test de la méthode setIdForm($idForm) |
||
47 | */ |
||
48 | public function testSetIdForm() |
||
49 | { |
||
50 | $this->mock->setIdForm('test'); |
||
51 | $this->string($this->mock->idForm)->isEqualTo('test'); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Test de la méthode tokenCreate() |
||
56 | */ |
||
57 | public function testTokenCreate() |
||
58 | { |
||
59 | $_SESSION = array(); |
||
60 | |||
61 | $this->mock->setIdForm('test'); |
||
62 | $token = $this->mock->tokenCreate(); |
||
63 | |||
64 | $this->variable($_SESSION['token']['test'])->isNotNull(); |
||
65 | $this->variable($_SESSION['token']['test']['token'])->isNotNull(); |
||
66 | $this->variable($_SESSION['token']['test']['date'])->isNotNull(); |
||
67 | |||
68 | $this->string($token)->isEqualTo($_SESSION['token']['test']['token']); |
||
69 | |||
70 | $this->exception(function() |
||
71 | { |
||
72 | $mock = new MockForm(); |
||
73 | $mock->tokenCreate(); |
||
74 | })->message->contains('Form name is undefined.'); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Test de la méthode tokenVerif() |
||
79 | */ |
||
80 | public function testTokenVerif() |
||
81 | { |
||
82 | $_SESSION = array(); |
||
83 | |||
84 | $this->mock->setIdForm('test'); |
||
85 | $token = $this->mock->tokenCreate(); |
||
86 | |||
87 | $_POST['token'] = $token; |
||
88 | $this->boolean($this->mock->tokenVerif())->isTrue(); |
||
89 | |||
90 | |||
91 | //Test avec la limite des 15 minutes dépassé |
||
92 | $token = $this->mock->tokenCreate(); |
||
93 | $_POST['token'] = $token; |
||
94 | |||
95 | $date = $_SESSION['token']['test']['date']; |
||
96 | $date = new \BFW\Date($date); |
||
97 | $date->modify('-30 minutes'); |
||
98 | $_SESSION['token']['test']['date'] = $date->getDate(); |
||
99 | $this->boolean($this->mock->tokenVerif())->isFalse(); |
||
100 | |||
101 | |||
102 | //Test avec un mauvais token |
||
103 | $this->mock->tokenCreate(); |
||
104 | $_POST['token'] = 'test'; |
||
105 | $this->boolean($this->mock->tokenVerif())->isFalse(); |
||
106 | } |
||
107 | |||
108 | } |
||
109 | |||
121 |