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\Model\PassesValidator\Validators\SkipGoogleTagManager; |
13
|
|
|
use Magento\Framework\App\Response\Http; |
14
|
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
16
|
|
|
|
17
|
|
|
class SkipGoogleTagManagerTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var Http |
21
|
|
|
*/ |
22
|
|
|
private $http; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var SkipGoogleTagManager |
26
|
|
|
*/ |
27
|
|
|
private $model; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Sets up the fixture |
31
|
|
|
*/ |
32
|
|
|
protected function setUp() |
33
|
|
|
{ |
34
|
|
|
$this->http = (new ObjectManager($this))->getObject(Http::class); |
35
|
|
|
$this->model = (new ObjectManager($this))->getObject(SkipGoogleTagManager::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
private function getScriptSkipped(): string |
42
|
|
|
{ |
43
|
|
|
return '<script type="text/javascript">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push( |
44
|
|
|
{\'gtm.start\': new Date().getTime(),event:\'gtm.js\'});var f=d.getElementsByTagName(s)[0], |
45
|
|
|
j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src= |
46
|
|
|
\'//www.googletagmanager.com/gtm.js?id=\'+i+dl;f.parentNode.insertBefore(j,f); |
47
|
|
|
})(window,document,\'script\',\'dataLayer\',\'GTM-FFFFFFF\');</script>'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getScriptNoSkipped(): string |
54
|
|
|
{ |
55
|
|
|
return '<script> <!-- ko i18n: \'test\' --> <!-- /ko --> </script>'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* |
60
|
|
|
*/ |
61
|
|
|
public function testSkipScript(): void |
62
|
|
|
{ |
63
|
|
|
$this->assertEquals(true, $this->model->validate($this->getScriptSkipped(), $this->http)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* |
68
|
|
|
*/ |
69
|
|
|
public function testNoSkipScript(): void |
70
|
|
|
{ |
71
|
|
|
$this->assertEquals(false, $this->model->validate($this->getScriptNoSkipped(), $this->http)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths