889cfd0074db52cc4be4ff0bf30dda6e8e67025b
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Tests / Unit / KeypairTest.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Tests\Unit;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Oliver Klee <typo3-coding@oliverklee.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 use TYPO3\CMS\Rsaauth\Keypair;
30
31 /**
32 * Test case.
33 *
34 * @author Oliver Klee <typo3-coding@oliverklee.de>
35 */
36 class KeypairTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
37 /**
38 * @var Keypair
39 */
40 protected $subject = NULL;
41
42 public function setUp() {
43 $this->subject = new Keypair();
44 }
45
46 /**
47 * @test
48 */
49 public function classIsSingleton() {
50 $this->assertInstanceOf(
51 'TYPO3\\CMS\\Core\\SingletonInterface',
52 $this->subject
53 );
54 }
55
56 /**
57 * @test
58 */
59 public function getExponentInitiallyReturnsZero() {
60 $this->assertSame(
61 0,
62 $this->subject->getExponent()
63 );
64 }
65
66 /**
67 * @test
68 */
69 public function setExponentSetsExponent() {
70 $this->subject->setExponent(123456);
71
72 $this->assertSame(
73 123456,
74 $this->subject->getExponent()
75 );
76 }
77
78 /**
79 * @test
80 *
81 * @expectedException \BadMethodCallException
82 */
83 public function setExponentCalledTwoTimesThrowsException() {
84 $this->subject->setExponent(123456);
85 $this->subject->setExponent(123456);
86 }
87
88 /**
89 * @test
90 */
91 public function getPrivateKeyInitiallyReturnsEmptyString() {
92 $this->assertSame(
93 '',
94 $this->subject->getPrivateKey()
95 );
96 }
97
98 /**
99 * @test
100 */
101 public function setPrivateKeySetsPrivateKey() {
102 $this->subject->setPrivateKey('foo bar');
103
104 $this->assertSame(
105 'foo bar',
106 $this->subject->getPrivateKey()
107 );
108 }
109
110 /**
111 * @test
112 *
113 * @expectedException \BadMethodCallException
114 */
115 public function setPrivateKeyCalledTwoTimesThrowsException() {
116 $this->subject->setPrivateKey('foo');
117 $this->subject->setPrivateKey('foo');
118 }
119
120 /**
121 * @test
122 */
123 public function getPublicKeyModulusInitiallyReturnsZero() {
124 $this->assertSame(
125 0,
126 $this->subject->getPublicKeyModulus()
127 );
128 }
129
130 /**
131 * @test
132 */
133 public function setPublicKeySetsPublicKeyModulus() {
134 $this->subject->setPublicKey(123456);
135
136 $this->assertSame(
137 123456,
138 $this->subject->getPublicKeyModulus()
139 );
140 }
141
142 /**
143 * @test
144 *
145 * @expectedException \BadMethodCallException
146 */
147 public function setPublicKeyCalledTwoTimesThrowsException() {
148 $this->subject->setPublicKey(123456);
149 $this->subject->setPublicKey(123456);
150 }
151
152 /**
153 * @test
154 */
155 public function isReadyForExponentSetAndPrivateKeySetAndPublicKeyModulusSetReturnsTrue() {
156 $this->subject->setExponent(1861234);
157 $this->subject->setPrivateKey('lkjasbe');
158 $this->subject->setPublicKey(745786268712);
159
160 $this->assertTrue(
161 $this->subject->isReady()
162 );
163 }
164
165 /**
166 * @test
167 */
168 public function isReadyForNothingSetReturnsFalse() {
169 $this->assertFalse(
170 $this->subject->isReady()
171 );
172 }
173
174 /**
175 * @test
176 */
177 public function isReadyForExponentSetAndPrivateKeySetAndPublicKeyModulusMissingReturnsFalse() {
178 $this->subject->setExponent(1861234);
179 $this->subject->setPrivateKey('lkjasbe');
180
181 $this->assertFalse(
182 $this->subject->isReady()
183 );
184 }
185
186 /**
187 * @test
188 */
189 public function isReadyForExponentSetAndPrivateMissingSetAndPublicKeyModulusSetReturnsFalse() {
190 $this->subject->setExponent(1861234);
191 $this->subject->setPublicKey(745786268712);
192
193 $this->assertFalse(
194 $this->subject->isReady()
195 );
196 }
197
198 /**
199 * @test
200 */
201 public function isReadyForExponentMissingAndPrivateKeySetAndPublicKeyModulusSetReturnsFalse() {
202 $this->subject->setPrivateKey('lkjasbe');
203 $this->subject->setPublicKey(745786268712);
204
205 $this->assertFalse(
206 $this->subject->isReady()
207 );
208 }
209 }