|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Test\Skautis; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
|
6
|
|
|
use Skautis\Config; |
|
7
|
|
|
use Skautis\DynamicPropertiesDisabledException; |
|
8
|
|
|
use Skautis\Skautis; |
|
9
|
|
|
use Skautis\User; |
|
10
|
|
|
use Skautis\Wsdl\WebServiceName; |
|
11
|
|
|
use Skautis\Wsdl\WsdlManager; |
|
12
|
|
|
|
|
13
|
|
|
class SkautisTest extends PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
protected function tearDown() |
|
17
|
|
|
{ |
|
18
|
|
|
\Mockery::close(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testSingletonSameId(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$skautis = Skautis::getInstance('asd'); |
|
24
|
|
|
$skautisA = Skautis::getInstance('asd'); |
|
25
|
|
|
$this->assertSame($skautis, $skautisA); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testSingletonDifferentId(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$skautis = Skautis::getInstance('asd'); |
|
31
|
|
|
$skautisA = Skautis::getInstance('qwe'); |
|
32
|
|
|
$this->assertNotSame($skautis, $skautisA); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testSingletonTestMode(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$appId = 'some-app-id'; |
|
38
|
|
|
|
|
39
|
|
|
$skautisWithTestMode = Skautis::getInstance($appId, Config::TEST_MODE_ENABLED); |
|
40
|
|
|
$skautisWithoutTestMode = Skautis::getInstance($appId, Config::TEST_MODE_DISABLED); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertNotSame($skautisWithTestMode, $skautisWithoutTestMode); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testGettingService(): void { |
|
46
|
|
|
$skautis = Skautis::getInstance('asd'); |
|
47
|
|
|
|
|
48
|
|
|
$serviceA = $skautis->UserManagement; |
|
49
|
|
|
$serviceB = $skautis->getWebService(WebServiceName::USER_MANAGEMENT); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertSame($serviceA, $serviceB); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testGettingServiceUsingAlias(): void { |
|
55
|
|
|
$skautis = Skautis::getInstance('asd'); |
|
56
|
|
|
|
|
57
|
|
|
$serviceA = $skautis->UserManagement; |
|
58
|
|
|
$serviceB = $skautis->user; |
|
|
|
|
|
|
59
|
|
|
$serviceC = $skautis->usr; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$this->assertSame($serviceA, $serviceB); |
|
62
|
|
|
$this->assertSame($serviceB, $serviceC); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testSettingWebService(): void { |
|
66
|
|
|
$skautis = Skautis::getInstance('asd'); |
|
67
|
|
|
|
|
68
|
|
|
$this->expectException(DynamicPropertiesDisabledException::class); |
|
69
|
|
|
$skautis->UserManagement = 'asd'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testGetLoginURL(): void { |
|
73
|
|
|
$skautis = Skautis::getInstance('asd'); |
|
74
|
|
|
$urlEncodedAddress = 'https://is.skaut.cz/Login/?appid=asd&ReturnUrl=https%3A%2F%2Fmy-web.nowhere%2Fasd'; |
|
75
|
|
|
$this->assertEquals($urlEncodedAddress, $skautis->getLoginUrl('https://my-web.nowhere/asd')); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
public function testGetLogoutURL(): void { |
|
80
|
|
|
|
|
81
|
|
|
/** @var User $user */ |
|
82
|
|
|
$user = \Mockery::mock(User::class); |
|
83
|
|
|
$user->shouldReceive('getLoginId') |
|
|
|
|
|
|
84
|
|
|
->once() |
|
85
|
|
|
->andReturn('log://123out'); |
|
86
|
|
|
|
|
87
|
|
|
/** @var WsdlManager $wsdlManager */ |
|
88
|
|
|
$config = new Config('asd'); |
|
89
|
|
|
$wsdlManager = \Mockery::mock(WsdlManager::class); |
|
90
|
|
|
$wsdlManager->shouldReceive('getConfig') |
|
91
|
|
|
->andReturn($config); |
|
92
|
|
|
|
|
93
|
|
|
$skautis = new Skautis($wsdlManager, $user); |
|
94
|
|
|
|
|
95
|
|
|
$urlEncodedAddress = 'https://test-is.skaut.cz/Login/LogOut.aspx?appid=asd&token=log%3A%2F%2F123out'; |
|
96
|
|
|
$this->assertEquals($urlEncodedAddress, $skautis->getLogoutUrl()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testGetRegisterURL(): void { |
|
100
|
|
|
$skautis = Skautis::getInstance('asd'); |
|
101
|
|
|
$urlEncodedAddress = 'https://is.skaut.cz/Login/Registration.aspx?appid=asd'; |
|
102
|
|
|
$this->assertEquals($urlEncodedAddress, $skautis->getRegisterUrl()); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testEventSetter(): void |
|
106
|
|
|
{ |
|
107
|
|
|
//@TODO |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.