Repository navigation
Expand file tree
/
Copy pathResponseTest.php
More file actions
72 lines (62 loc) · 2.03 KB
/
Copy pathResponseTest.php
File metadata and controls
72 lines (62 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Patchstack\Response;
final class ResponseTest extends TestCase
{
protected $app;
/**
* Setup the test for testing the header location redirect.
*
* @return void
*/
protected function setUp(): void
{
$this->app = $this->getMockBuilder(Response::class)->setConstructorArgs([])->onlyMethods(['redirect'])->getMock();
$this->app->expects($this->any())->method('redirect')->will(
$this->returnCallback(
function ($url) {
throw new \Exception($url);
}
)
);
}
/**
* Test a redirect with a valid URL.
*
* @return void
*/
public function testRedirectSuccess()
{
try {
$this->app->redirect('https://www.amazon.com', true);
} catch (\Exception $e) {
$this->assertEquals($e->getMessage(), 'https://www.amazon.com');
}
try {
$this->app->redirect('https://www.google.com', true);
} catch (\Exception $e) {
$this->assertEquals($e->getMessage(), 'https://www.google.com');
}
try {
$this->app->redirect('https://1.1.1.1', true);
} catch (\Exception $e) {
$this->assertEquals($e->getMessage(), 'https://1.1.1.1');
}
}
/**
* Test a redirect which has an invalid URL.
* Since users can supply this redirect URL, we'd want to check it on the client side too.
*
* @return void
*/
public function testRedirectFailure()
{
$response = new Response();
$this->assertEquals($response->redirect('https//patchstack.com', true), false);
$this->assertEquals($response->redirect('https:/patchstackcom', true), false);
$this->assertEquals($response->redirect('$TOJ34r8tq94ht', true), false);
$this->assertEquals($response->redirect('123.123.123', true), false);
$this->assertEquals($response->redirect(' ', true), false);
}
}