1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. |
4
|
|
|
* @author: <mailto:[email protected]> |
5
|
|
|
* @github: <https://github.com/hryvinskyi> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Hryvinskyi\DeferJs\Test\Unit\Model\PassesValidator\Validators; |
11
|
|
|
|
12
|
|
|
use Hryvinskyi\DeferJs\Helper\Config; |
13
|
|
|
use Hryvinskyi\DeferJs\Model\PassesValidator\Validators\SkipScriptByAttribute; |
14
|
|
|
use Hryvinskyi\DeferJs\Model\PassesValidator\Validators\SkipScriptsByController; |
15
|
|
|
use Magento\Framework\App\Request\Http as RequestHttp; |
16
|
|
|
use Magento\Framework\App\Response\Http; |
17
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
20
|
|
|
|
21
|
|
|
class SkipScriptByControllerTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Config|PHPUnit_Framework_MockObject_MockObject |
25
|
|
|
*/ |
26
|
|
|
private $config; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var RequestHttp|PHPUnit_Framework_MockObject_MockObject |
30
|
|
|
*/ |
31
|
|
|
private $request; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Http |
35
|
|
|
*/ |
36
|
|
|
private $http; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var SkipScriptByAttribute |
40
|
|
|
*/ |
41
|
|
|
private $model; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Sets up the fixture |
45
|
|
|
*/ |
46
|
|
|
protected function setUp() |
47
|
|
|
{ |
48
|
|
|
$this->config = $this->createPartialMock( |
49
|
|
|
Config::class, |
50
|
|
|
['getExcludeControllers'] |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->request = $this->createPartialMock( |
54
|
|
|
RequestHttp::class, |
55
|
|
|
['getModuleName', 'getControllerName', 'getActionName'] |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->config->expects($this->any())->method('getExcludeControllers') |
59
|
|
|
->willReturn('{"_1554036929376_376":{"controller":"cms_index_index"}}'); |
60
|
|
|
$this->request->expects($this->any())->method('getControllerName')->willReturn('index'); |
61
|
|
|
$this->request->expects($this->any())->method('getActionName')->willReturn('index'); |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
$this->http = (new ObjectManager($this))->getObject(Http::class); |
65
|
|
|
$this->model = (new ObjectManager($this))->getObject(SkipScriptsByController::class, [ |
66
|
|
|
'config' => $this->config, |
67
|
|
|
'request' => $this->request, |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
*/ |
74
|
|
|
public function testSkipScript(): void |
75
|
|
|
{ |
76
|
|
|
$this->request->expects($this->any())->method('getModuleName')->willReturn('cms'); |
77
|
|
|
$this->assertEquals(true, $this->model->validate('', $this->http)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
*/ |
83
|
|
|
public function testNoSkipScript(): void |
84
|
|
|
{ |
85
|
|
|
$this->request->expects($this->any())->method('getModuleName')->willReturn('category'); |
86
|
|
|
$this->assertEquals(false, $this->model->validate('', $this->http)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|