Completed
Push — master ( 54a566...4b76f9 )
by Vuong
01:44
created

AdaptiveFilterTest::testDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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