Passed
Push — master ( 2cd729...512691 )
by Володимир
03:34
created

SkipScriptByAttributeTest::getBodyNoSkipped()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.9666
c 0
b 0
f 0
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 Magento\Framework\App\Response\Http;
15
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
class SkipScriptByAttributeTest extends TestCase
19
{
20
    const DEFAULT_SKIP_TAG = 'data-deferjs="false"';
21
22
    /**
23
     * @var Config|\PHPUnit_Framework_MockObject_MockObject
24
     */
25
    private $config;
26
27
    /**
28
     * @var Http
29
     */
30
    private $http;
31
32
    /**
33
     * @var SkipScriptByAttribute
34
     */
35
    private $model;
36
37
    /**
38
     * Sets up the fixture
39
     */
40
    protected function setUp()
41
    {
42
        $this->config = $this->createPartialMock(
43
            Config::class,
44
            ['getDisableAttribute']
45
        );
46
        $this->config->expects($this->any())->method('getDisableAttribute')->willReturn(self::DEFAULT_SKIP_TAG);
47
        $this->http = (new ObjectManager($this))->getObject(Http::class);
48
        $this->model = (new ObjectManager($this))->getObject(SkipScriptByAttribute::class, [
49
            'config' => $this->config
50
        ]);
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    private function getBodySkipped(): string
57
    {
58
        return '<!DOCTYPE html>' .
59
            '<html>' .
60
                '<head>' .
61
                    '<script ' . self::DEFAULT_SKIP_TAG . '> <!-- ko i18n: \'test\' --> <!-- /ko --> </script>' .
62
                '</head>' .
63
                '<body>' .
64
                    '<h1>My First Heading</h1>' .
65
                    '<p>My first paragraph.</p>' .
66
                '</body>' .
67
            '</html>';
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getBodyNoSkipped(): string
74
    {
75
        return '<!DOCTYPE html>' .
76
            '<html>' .
77
                '<head>' .
78
                    '<script> <!-- ko i18n: \'test\' --> <!-- /ko --> </script>' . '</head>' .
79
                '<body>' .
80
                    '<h1>My First Heading</h1>' .
81
                    '<p>My first paragraph.</p>' .
82
                '</body>' .
83
            '</html>';
84
    }
85
86
    /**
87
     *
88
     */
89
    public function testSkipScript(): void
90
    {
91
        $this->assertEquals(true, $this->model->validate($this->getBodySkipped(), $this->http));
92
    }
93
94
    /**
95
     *
96
     */
97
    public function testNoSkipScript(): void
98
    {
99
        $this->assertEquals(false, $this->model->validate($this->getBodyNoSkipped(), $this->http));
100
    }
101
}
102