[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Tests / Unit / KeypairTest.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Tests\Unit;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Rsaauth\Keypair;
18
19 /**
20 * Test case.
21 */
22 class KeypairTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
23 {
24 /**
25 * @var Keypair
26 */
27 protected $subject = null;
28
29 protected function setUp()
30 {
31 $this->subject = new Keypair();
32 }
33
34 /**
35 * @test
36 */
37 public function classIsSingleton()
38 {
39 $this->assertInstanceOf(
40 \TYPO3\CMS\Core\SingletonInterface::class,
41 $this->subject
42 );
43 }
44
45 /**
46 * @test
47 */
48 public function getExponentInitiallyReturnsZero()
49 {
50 $this->assertSame(
51 0,
52 $this->subject->getExponent()
53 );
54 }
55
56 /**
57 * @test
58 */
59 public function setExponentSetsExponent()
60 {
61 $this->subject->setExponent(123456);
62
63 $this->assertSame(
64 123456,
65 $this->subject->getExponent()
66 );
67 }
68
69 /**
70 * @test
71 *
72 */
73 public function setExponentCalledTwoTimesThrowsException()
74 {
75 $this->expectException(\BadMethodCallException::class);
76 $this->expectExceptionCode(1296062830);
77 $this->subject->setExponent(123456);
78 $this->subject->setExponent(123456);
79 }
80
81 /**
82 * @test
83 */
84 public function getPrivateKeyInitiallyReturnsEmptyString()
85 {
86 $this->assertSame(
87 '',
88 $this->subject->getPrivateKey()
89 );
90 }
91
92 /**
93 * @test
94 */
95 public function setPrivateKeySetsPrivateKey()
96 {
97 $this->subject->setPrivateKey('foo bar');
98
99 $this->assertSame(
100 'foo bar',
101 $this->subject->getPrivateKey()
102 );
103 }
104
105 /**
106 * @test
107 *
108 */
109 public function setPrivateKeyCalledTwoTimesThrowsException()
110 {
111 $this->expectException(\BadMethodCallException::class);
112 $this->expectExceptionCode(1296062831);
113 $this->subject->setPrivateKey('foo');
114 $this->subject->setPrivateKey('foo');
115 }
116
117 /**
118 * @test
119 */
120 public function getPublicKeyModulusInitiallyReturnsZero()
121 {
122 $this->assertSame(
123 0,
124 $this->subject->getPublicKeyModulus()
125 );
126 }
127
128 /**
129 * @test
130 */
131 public function setPublicKeySetsPublicKeyModulus()
132 {
133 $this->subject->setPublicKey(123456);
134
135 $this->assertSame(
136 123456,
137 $this->subject->getPublicKeyModulus()
138 );
139 }
140
141 /**
142 * @test
143 *
144 */
145 public function setPublicKeyCalledTwoTimesThrowsException()
146 {
147 $this->expectException(\BadMethodCallException::class);
148 $this->expectExceptionCode(1296062832);
149 $this->subject->setPublicKey(123456);
150 $this->subject->setPublicKey(123456);
151 }
152
153 /**
154 * @test
155 */
156 public function isReadyForExponentSetAndPrivateKeySetAndPublicKeyModulusSetReturnsTrue()
157 {
158 $this->subject->setExponent(1861234);
159 $this->subject->setPrivateKey('lkjasbe');
160 $this->subject->setPublicKey(745786268712);
161
162 $this->assertTrue(
163 $this->subject->isReady()
164 );
165 }
166
167 /**
168 * @test
169 */
170 public function isReadyForNothingSetReturnsFalse()
171 {
172 $this->assertFalse(
173 $this->subject->isReady()
174 );
175 }
176
177 /**
178 * @test
179 */
180 public function isReadyForExponentSetAndPrivateKeySetAndPublicKeyModulusMissingReturnsFalse()
181 {
182 $this->subject->setExponent(1861234);
183 $this->subject->setPrivateKey('lkjasbe');
184
185 $this->assertFalse(
186 $this->subject->isReady()
187 );
188 }
189
190 /**
191 * @test
192 */
193 public function isReadyForExponentSetAndPrivateMissingSetAndPublicKeyModulusSetReturnsFalse()
194 {
195 $this->subject->setExponent(1861234);
196 $this->subject->setPublicKey(745786268712);
197
198 $this->assertFalse(
199 $this->subject->isReady()
200 );
201 }
202
203 /**
204 * @test
205 */
206 public function isReadyForExponentMissingAndPrivateKeySetAndPublicKeyModulusSetReturnsFalse()
207 {
208 $this->subject->setPrivateKey('lkjasbe');
209 $this->subject->setPublicKey(745786268712);
210
211 $this->assertFalse(
212 $this->subject->isReady()
213 );
214 }
215 }