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\SkipScriptsByURLPattern; |
14
|
|
|
use Magento\Framework\App\Request\Http as RequestHttp; |
15
|
|
|
use Magento\Framework\App\Response\Http; |
16
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
19
|
|
|
|
20
|
|
|
class SkipScriptsByURLPatternTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Config|PHPUnit_Framework_MockObject_MockObject |
24
|
|
|
*/ |
25
|
|
|
private $config; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var RequestHttp|PHPUnit_Framework_MockObject_MockObject |
29
|
|
|
*/ |
30
|
|
|
private $request; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var Http |
34
|
|
|
*/ |
35
|
|
|
private $http; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var SkipScriptsByURLPattern |
39
|
|
|
*/ |
40
|
|
|
private $model; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Sets up the fixture |
44
|
|
|
*/ |
45
|
|
|
protected function setUp() |
46
|
|
|
{ |
47
|
|
|
$this->config = $this->createPartialMock( |
48
|
|
|
Config::class, |
49
|
|
|
['getExcludeUrlPattern'] |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$this->request = $this->createPartialMock( |
53
|
|
|
RequestHttp::class, |
54
|
|
|
['getRequestUri'] |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$this->config->expects($this->any())->method('getExcludeUrlPattern') |
58
|
|
|
->willReturn('{"_1589359003110_110":{"pattern":"*argus-all-weather*"}}'); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->http = (new ObjectManager($this))->getObject(Http::class); |
62
|
|
|
$this->model = (new ObjectManager($this))->getObject(SkipScriptsByURLPattern::class, [ |
63
|
|
|
'config' => $this->config, |
64
|
|
|
'request' => $this->request, |
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* |
70
|
|
|
*/ |
71
|
|
|
public function testSkipScript(): void |
72
|
|
|
{ |
73
|
|
|
$this->request->expects($this->any())->method('getRequestUri')->willReturn('/argus-all-weather-tank.html'); |
74
|
|
|
$this->assertEquals(true, $this->model->validate('', $this->http)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* |
79
|
|
|
*/ |
80
|
|
|
public function testNoSkipScript(): void |
81
|
|
|
{ |
82
|
|
|
$this->request->expects($this->any())->method('getRequestUri')->willReturn('/someUrl.html'); |
83
|
|
|
$this->assertEquals(false, $this->model->validate('', $this->http)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|