1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakePHP Plugin : CakePHP Subdomain Routing |
4
|
|
|
* Copyright (c) Multidimension.al (http://multidimension.al) |
5
|
|
|
* Github : https://github.com/multidimension-al/cakephp-subdomains |
6
|
|
|
* |
7
|
|
|
* Licensed under The MIT License |
8
|
|
|
* For full copyright and license information, please see the LICENSE file |
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
10
|
|
|
* |
11
|
|
|
* @copyright (c) Multidimension.al (http://multidimension.al) |
12
|
|
|
* @link https://github.com/multidimension-al/cakephp-subdomains Github |
13
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Multidimensional\Subdomains\Tests\TestCase\Middleware; |
17
|
|
|
|
18
|
|
|
use Cake\Core\Configure; |
19
|
|
|
use Cake\TestSuite\IntegrationTestCase; |
20
|
|
|
use Multidimensional\Subdomains\Middleware\SubdomainMiddleware; |
21
|
|
|
|
22
|
|
|
class SubdomainMiddlewareTest extends IntegrationTestCase |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
private $subdomainMiddleware; |
26
|
|
|
private $defaultSubdomains; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function setUp() |
32
|
|
|
{ |
33
|
|
|
parent::setUp(); |
34
|
|
|
Configure::write('Multidimensional/Subdomains.Subdomains', ['admin']); |
35
|
|
|
$this->subdomainMiddleware = new SubdomainMiddleware(); |
36
|
|
|
$this->defaultSubdomains = $this->subdomainMiddleware->defaultSubdomains; |
37
|
|
|
$this->useHttpServer(true); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function tearDown() |
44
|
|
|
{ |
45
|
|
|
parent::tearDown(); |
46
|
|
|
Configure::delete('Multidimensional/Subdomains.Subdomains'); |
47
|
|
|
unset($this->subdomainMiddleware); |
48
|
|
|
unset($this->defaultSubdomains); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function testGetSubdomains() |
55
|
|
|
{ |
56
|
|
|
$subdomains = $this->subdomainMiddleware->getSubdomains(); |
57
|
|
|
$this->assertEquals($subdomains, array_merge($this->defaultSubdomains, ['admin'])); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function testGetPrefixAndHost() |
64
|
|
|
{ |
65
|
|
|
$array = $this->subdomainMiddleware->getPrefixAndHost('admin.example.com'); |
66
|
|
|
$this->assertEquals($array, ['admin', 'example.com']); |
67
|
|
|
$array = $this->subdomainMiddleware->getPrefixAndHost('subdomain.example.com'); |
68
|
|
|
$this->assertEquals($array, [false, 'example.com']); |
69
|
|
|
$array = $this->subdomainMiddleware->getPrefixAndHost('example.com'); |
70
|
|
|
$this->assertEquals($array, [false, 'example.com']); |
71
|
|
|
$array = $this->subdomainMiddleware->getPrefixAndHost('www.example.com'); |
72
|
|
|
$this->assertEquals($array, ['www', 'example.com']); |
73
|
|
|
$array = $this->subdomainMiddleware->getPrefixAndHost('false.example.com'); |
74
|
|
|
$this->assertEquals($array, ['false', 'example.com']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function testInvoke() |
81
|
|
|
{ |
82
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
83
|
|
|
/*$this->configRequest(['uri' => ['_host' => 'admin.example.com']]); |
84
|
|
|
$request = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock(); |
85
|
|
|
$response = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock(); |
86
|
|
|
$this->subdomainMiddleware->__invoke($request, $resposne, $name);*/ |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|