|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Firesphere\StripeSlack\Test; |
|
4
|
|
|
|
|
5
|
|
|
use Firesphere\StripeSlack\Controller\SlackAuthController; |
|
6
|
|
|
use GuzzleHttp\Client; |
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use SilverStripe\Control\Director; |
|
9
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
10
|
|
|
use SilverStripe\Control\HTTPResponse; |
|
11
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
12
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
13
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Test various items on the SlackAuthController |
|
17
|
|
|
* |
|
18
|
|
|
* Class SlackAuthControllerTest |
|
19
|
|
|
*/ |
|
20
|
|
|
class SlackAuthControllerTest extends SapphireTest |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var SlackAuthController |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $controller; |
|
26
|
|
|
|
|
27
|
|
|
public function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->controller = Injector::inst()->get(SlackAuthController::class); |
|
30
|
|
|
parent::setUp(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function tearDown() |
|
34
|
|
|
{ |
|
35
|
|
|
parent::tearDown(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetQuery() |
|
39
|
|
|
{ |
|
40
|
|
|
$config = SiteConfig::current_site_config(); |
|
41
|
|
|
$result = $this->controller->getQuery($config, '1234567890987654321'); |
|
42
|
|
|
$expectedArray = [ |
|
43
|
|
|
'client_id' => $config->SlackClientID, |
|
44
|
|
|
'client_secret' => $config->SlackClientSecret, |
|
45
|
|
|
'code' => '1234567890987654321', |
|
46
|
|
|
'redirect_uri' => Director::absoluteURL('/SlackAuthorization/'), |
|
47
|
|
|
]; |
|
48
|
|
|
$expected = http_build_query($expectedArray); |
|
49
|
|
|
$this->assertEquals($expected, $result); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testSaveToken() |
|
53
|
|
|
{ |
|
54
|
|
|
$response = new HTTPResponse('{"access_token":"12345678chdiyp67"}'); |
|
55
|
|
|
|
|
56
|
|
|
$config = SiteConfig::current_site_config(); |
|
57
|
|
|
|
|
58
|
|
|
$this->controller->saveToken($response, $config); |
|
|
|
|
|
|
59
|
|
|
$config = SiteConfig::current_site_config(); |
|
60
|
|
|
// This seems to not work on tests?? SiteConfig seems to not write |
|
61
|
|
|
$this->assertEquals('12345678chdiyp67', $config->SlackToken); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testGetConfig() |
|
65
|
|
|
{ |
|
66
|
|
|
$controller = SlackAuthController::create(); |
|
67
|
|
|
$config = SiteConfig::current_site_config(); |
|
68
|
|
|
$config->SlackURL = 'https://team.slack.com'; |
|
69
|
|
|
$config->write(); |
|
70
|
|
|
$result = $controller->getConfig(new HTTPRequest('GET', 'https://team.slack.com/api/something', ['code' => '1234567890'])); |
|
71
|
|
|
$this->assertEquals('1234567890', $result[0]); |
|
72
|
|
|
$this->assertInstanceOf(SiteConfig::class, $result[1]); |
|
73
|
|
|
$this->assertEquals($config->SlackURL . '/', $result[2]); |
|
74
|
|
|
$this->assertEquals('api/oauth.access?', $result[3]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|