1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lifeboat\Tests; |
4
|
|
|
|
5
|
|
|
use Lifeboat\App; |
6
|
|
|
use Lifeboat\Client; |
7
|
|
|
use Lifeboat\Exceptions\InvalidArgumentException; |
8
|
|
|
use Lifeboat\Utils\Utils; |
9
|
|
|
|
10
|
|
|
class AppTest extends Connector { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @test |
14
|
|
|
* @covers \Lifeboat\App::__construct |
15
|
|
|
* @covers \Lifeboat\App::getAppID |
16
|
|
|
* @covers \Lifeboat\App::getAppSecret |
17
|
|
|
* @covers \Lifeboat\App::setAppID |
18
|
|
|
* @covers \Lifeboat\App::setAppSecret |
19
|
|
|
*/ |
20
|
|
|
public function testConstruct() |
21
|
|
|
{ |
22
|
|
|
$app = new App('app_id', 'secret'); |
23
|
|
|
$this->assertInstanceOf(App::class, $app); |
24
|
|
|
|
25
|
|
|
$this->assertEquals('app_id', $app->getAppID()); |
26
|
|
|
$this->assertEquals('secret', $app->getAppSecret()); |
27
|
|
|
|
28
|
|
|
$this->expectException(InvalidArgumentException::class); |
29
|
|
|
new App('', ''); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @test |
34
|
|
|
* @covers \Lifeboat\App::getAPIChallenge |
35
|
|
|
* @covers \Lifeboat\App::setAPIChallenge |
36
|
|
|
*/ |
37
|
|
|
public function testChallenge() |
38
|
|
|
{ |
39
|
|
|
$app = new App('mock', 'mock'); |
40
|
|
|
|
41
|
|
|
$challenge = '123'; |
42
|
|
|
$app->setAPIChallenge($challenge); |
43
|
|
|
$this->assertEquals($challenge, $app->getAPIChallenge()); |
44
|
|
|
|
45
|
|
|
$app->setAPIChallenge(''); |
46
|
|
|
$this->assertEquals(128, strlen($app->getAPIChallenge())); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @test |
51
|
|
|
* @covers \Lifeboat\App::getAuthURL |
52
|
|
|
*/ |
53
|
|
|
public function testAuthURL() |
54
|
|
|
{ |
55
|
|
|
$app = new App('id', 'secret', 'http://test.domain'); |
56
|
|
|
$url = $app->getAuthURL('process.php', 'error.php', 'challenge'); |
57
|
|
|
$expect = 'http://test.domain/oauth/code?app_id=id&process_url=' . |
58
|
|
|
urlencode('process.php') . |
59
|
|
|
'&error_url=' . urlencode('error.php') . |
60
|
|
|
'&challenge=' . Utils::pack('challenge'); |
61
|
|
|
|
62
|
|
|
$this->assertEquals($expect, $url); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|