|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/vuongxuongminh/yii2-mobile-first |
|
4
|
|
|
* @copyright Copyright (c) 2019 Vuong Xuong Minh |
|
5
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace vxm\test\unit\mobileFirst; |
|
9
|
|
|
|
|
10
|
|
|
use Yii; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class AdaptiveFilterTest |
|
14
|
|
|
* |
|
15
|
|
|
* @author Vuong Minh <[email protected]> |
|
16
|
|
|
* @since 1.0.0 |
|
17
|
|
|
*/ |
|
18
|
|
|
class AdaptiveFilterTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
public function testRedirect() |
|
22
|
|
|
{ |
|
23
|
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1'; |
|
24
|
|
|
Yii::$app->runAction('test/test'); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertNotNull(Yii::$app->response->headers->get('location', null)); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testNotRedirect() |
|
30
|
|
|
{ |
|
31
|
|
|
$_SERVER['HTTP_USER_AGENT'] = null; |
|
32
|
|
|
Yii::$app->runAction('test/test'); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertNull(Yii::$app->response->headers->get('location', null)); |
|
35
|
|
|
|
|
36
|
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1'; |
|
37
|
|
|
Yii::$app->request->setHostInfo('http://abc.com'); |
|
38
|
|
|
Yii::$app->runAction('test/test'); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertNull(Yii::$app->response->headers->get('location', null)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testRedirectUrlException() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->expectException('\yii\base\InvalidConfigException'); |
|
46
|
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1'; |
|
47
|
|
|
Yii::$app->getBehavior('mobileFirst')->redirectUrl = null; |
|
48
|
|
|
Yii::$app->runAction('test/test'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testRequestMethod() |
|
52
|
|
|
{ |
|
53
|
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1'; |
|
54
|
|
|
$_SERVER['REQUEST_METHOD'] = 'DELETE'; |
|
55
|
|
|
Yii::$app->runAction('test/test'); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertNull(Yii::$app->response->headers->get('location', null)); |
|
58
|
|
|
|
|
59
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET'; |
|
60
|
|
|
Yii::$app->runAction('test/test'); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertNotNull(Yii::$app->response->headers->get('location', null)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|