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 ViewRenderBehaviorTest |
14
|
|
|
* |
15
|
|
|
* @author Vuong Minh <[email protected]> |
16
|
|
|
* @since 1.0.0 |
17
|
|
|
*/ |
18
|
|
|
class ViewRenderTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
public function testDefaultRender() |
22
|
|
|
{ |
23
|
|
|
$output = Yii::$app->runAction('test/test'); |
24
|
|
|
|
25
|
|
|
$this->assertEquals('default', trim($output)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function testMobileRender() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$_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'; |
31
|
|
|
$output = Yii::$app->runAction('test/test'); |
32
|
|
|
|
33
|
|
|
$this->assertEquals('mobile', trim($output)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function testTabletRender() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'; |
39
|
|
|
$output = Yii::$app->runAction('test/test'); |
40
|
|
|
|
41
|
|
|
$this->assertEquals('tablet', trim($output)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testRestoreRenderer() |
45
|
|
|
{ |
46
|
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'; |
47
|
|
|
Yii::$app->runAction('test/test'); |
48
|
|
|
|
49
|
|
|
$this->assertEquals(TestRenderer::class, get_class(Yii::$app->getView()->renderers['php'])); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function mockApplication($config = [], $appClass = '\yii\web\Application'): void |
53
|
|
|
{ |
54
|
|
|
parent::mockApplication($config, $appClass); |
55
|
|
|
|
56
|
|
|
Yii::$app->getBehavior('mobileFirst')->detach(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.