Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
77.50% covered (warning)
77.50%
62 / 80
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_template_template_includecss_test
77.50% covered (warning)
77.50%
62 / 80
75.00% covered (warning)
75.00%
3 / 4
4.18
0.00% covered (danger)
0.00%
0 / 1
 setup_engine
100.00% covered (success)
100.00%
56 / 56
100.00% covered (success)
100.00%
1 / 1
1
 template_data
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
2
 test_includecss_compilation
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 test_include_css_compilation
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14require_once __DIR__ . '/template_test_case_with_tree.php';
15
16class phpbb_template_template_includecss_test extends phpbb_template_template_test_case_with_tree
17{
18    /** @var \phpbb\path_helper */
19    protected $phpbb_path_helper;
20
21    /** @var string */
22    protected $parent_template_path;
23
24    protected function setup_engine(array $new_config = array(), string $template_path = '')
25    {
26        global $phpbb_root_path, $phpEx, $user;
27
28        $defaults = $this->config_defaults();
29        $config = new \phpbb\config\config(array_merge($defaults, $new_config));
30
31        $filesystem = new \phpbb\filesystem\filesystem();
32
33        $this->phpbb_path_helper = new \phpbb\path_helper(
34            new \phpbb\symfony_request(
35                new phpbb_mock_request()
36            ),
37            $this->createMock('\phpbb\request\request'),
38            $phpbb_root_path,
39            $phpEx
40        );
41
42        $this->template_path = $this->test_path . '/templates';
43        $this->parent_template_path = $this->test_path . '/parent_templates';
44        $cache_path = $phpbb_root_path . 'cache/twig';
45        $context = new \phpbb\template\context();
46        $loader = new \phpbb\template\twig\loader('');
47        $log = new \phpbb\log\dummy();
48        $assets_bag = new \phpbb\template\assets_bag();
49        $twig = new \phpbb\template\twig\environment(
50            $assets_bag,
51            $config,
52            $filesystem,
53            $this->phpbb_path_helper,
54            $cache_path,
55            null,
56            $loader,
57            new \phpbb\event\dispatcher(),
58            array(
59                'cache'            => false,
60                'debug'            => false,
61                'auto_reload'    => true,
62                'autoescape'    => false,
63            )
64        );
65        $this->template = new phpbb\template\twig\twig(
66            $this->phpbb_path_helper,
67            $config,
68            $context,
69            $twig,
70            $cache_path,
71            $this->user,
72            array(new \phpbb\template\twig\extension($context, $twig, $this->user)),
73            new phpbb_mock_extension_manager(
74                __DIR__ . '/',
75                array(
76                    'include/css' => array(
77                        'ext_name' => 'include/css',
78                        'ext_active' => '1',
79                        'ext_path' => 'ext/include/css/',
80                    ),
81                )
82            )
83        );
84        $twig->setLexer(new \phpbb\template\twig\lexer($twig));
85        $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path));
86    }
87
88    public static function template_data()
89    {
90        return array(
91            /*
92            array(
93                // vars
94                // expected
95            ),
96            */
97            array(
98                array('TEST' => 1),
99                '<link href="tests/template/templates/child_only.css?assets_version=1" rel="stylesheet" media="screen">',
100            ),
101            array(
102                array('TEST' => 2),
103                '<link href="tests/template/parent_templates/parent_only.css?assets_version=1" rel="stylesheet" media="screen">',
104            ),
105            array(
106                array('TEST' => 3),
107                '<link href="tests/template/ext/include/css/styles/all/theme/test.css?assets_version=1" rel="stylesheet" media="screen">',
108            ),
109            array(
110                array('TEST' => 4),
111                '<link href="tests/template/ext/include/css/styles/all/theme/child_only.css?assets_version=1" rel="stylesheet" media="screen">',
112            ),
113        );
114    }
115
116    /**
117     * @dataProvider template_data
118     */
119    public function test_includecss_compilation($vars, $expected)
120    {
121        // Reset the engine state
122        $this->setup_engine(array('assets_version' => 1));
123
124        $this->template->assign_vars($vars);
125
126        // Run test
127        $this->run_template('includecss.html', array(), array(), array(), $expected);
128    }
129
130    /**
131     * @dataProvider template_data
132     */
133    public function test_include_css_compilation($vars, $expected)
134    {
135        // Reset the engine state
136        $this->setup_engine(array('assets_version' => 1));
137
138        $this->template->assign_vars($vars);
139
140        // Run test
141        $this->run_template('includecss_twig.html', array(), array(), array(), $expected);
142    }
143}