Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
35.54% |
43 / 121 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_template_template_events_test | |
35.54% |
43 / 121 |
|
33.33% |
1 / 3 |
11.70 | |
0.00% |
0 / 1 |
| template_data | |
0.00% |
0 / 77 |
|
0.00% |
0 / 1 |
2 | |||
| test_event | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| setup_engine_for_events | |
100.00% |
40 / 40 |
|
100.00% |
1 / 1 |
2 | |||
| 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 | |
| 14 | require_once __DIR__ . '/template_test_case.php'; |
| 15 | |
| 16 | class phpbb_template_template_events_test extends phpbb_template_template_test_case |
| 17 | { |
| 18 | protected $extension_manager; |
| 19 | |
| 20 | public static function template_data() |
| 21 | { |
| 22 | return array( |
| 23 | /* |
| 24 | array( |
| 25 | '', // Description |
| 26 | '', // dataset |
| 27 | array(), // style names |
| 28 | '', // file |
| 29 | array(), // vars |
| 30 | array(), // block vars |
| 31 | array(), // destroy |
| 32 | '', // expected result |
| 33 | ), |
| 34 | */ |
| 35 | array( |
| 36 | 'Simple template event', |
| 37 | 'ext_trivial', |
| 38 | array(), |
| 39 | 'event_simple.html', |
| 40 | array(), |
| 41 | array(), |
| 42 | array(), |
| 43 | "Simple in trivial extension.", |
| 44 | ), |
| 45 | array( |
| 46 | 'Universal template event ("all" style)', |
| 47 | 'ext_trivial', |
| 48 | array(), |
| 49 | 'event_universal.html', |
| 50 | array(), |
| 51 | array(), |
| 52 | array(), |
| 53 | "Universal in trivial extension.", |
| 54 | ), |
| 55 | array( |
| 56 | 'Template event with inheritance - parent', |
| 57 | 'event_inheritance', |
| 58 | array('silver'), |
| 59 | 'event_test.html', |
| 60 | array(), |
| 61 | array(), |
| 62 | array(), |
| 63 | 'Kappa test event in silver |
| 64 | Omega test event in silver |
| 65 | Zeta test event in all', |
| 66 | ), |
| 67 | array( |
| 68 | 'Template event with inheritance - child', |
| 69 | 'event_inheritance', |
| 70 | array('silver_inherit', 'silver'), |
| 71 | 'event_test.html', |
| 72 | array(), |
| 73 | array(), |
| 74 | array(), |
| 75 | 'Kappa test event in silver_inherit |
| 76 | Omega test event in silver |
| 77 | Zeta test event in all', |
| 78 | ), |
| 79 | array( |
| 80 | 'Definition in parent style', |
| 81 | 'event_inheritance', |
| 82 | array('silver_inherit', 'silver'), |
| 83 | 'event_two.html', |
| 84 | array(), |
| 85 | array(), |
| 86 | array(), |
| 87 | 'two in silver in omega', |
| 88 | ), |
| 89 | array( |
| 90 | 'EVENT in loop', |
| 91 | 'ext_trivial', |
| 92 | array('silver'), |
| 93 | 'event_loop.html', |
| 94 | array(), |
| 95 | array('event_loop' => array(array(), array(), array())), |
| 96 | array(), |
| 97 | 'event_loop0|event_loop1|event_loop2', |
| 98 | ), |
| 99 | array( |
| 100 | 'EVENT with subloop in loop', |
| 101 | 'ext_trivial', |
| 102 | array('silver'), |
| 103 | 'event_subloop.html', |
| 104 | array(), |
| 105 | array( |
| 106 | 'event_loop' => array(array()), |
| 107 | 'event_loop.subloop' => array(array()), |
| 108 | ), |
| 109 | array(), |
| 110 | 'event_loop[0[subloop:0]]', |
| 111 | ), |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @dataProvider template_data |
| 117 | */ |
| 118 | public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected, $incomplete_message = '') |
| 119 | { |
| 120 | if ($incomplete_message) |
| 121 | { |
| 122 | $this->markTestIncomplete($incomplete_message); |
| 123 | } |
| 124 | |
| 125 | // Reset the engine state |
| 126 | $this->setup_engine_for_events($dataset, $style_names); |
| 127 | |
| 128 | // Run test |
| 129 | $this->run_template($file, $vars, $block_vars, $destroy, $expected); |
| 130 | } |
| 131 | |
| 132 | protected function setup_engine_for_events($dataset, $style_names, array $new_config = array()) |
| 133 | { |
| 134 | global $phpbb_root_path, $phpEx, $user; |
| 135 | |
| 136 | $defaults = $this->config_defaults(); |
| 137 | $config = new \phpbb\config\config(array_merge($defaults, $new_config)); |
| 138 | |
| 139 | $this->template_path = __DIR__ . "/datasets/$dataset/styles/silver/template"; |
| 140 | $this->extension_manager = new phpbb_mock_filesystem_extension_manager( |
| 141 | __DIR__ . "/datasets/$dataset/" |
| 142 | ); |
| 143 | |
| 144 | $filesystem = new \phpbb\filesystem\filesystem(); |
| 145 | $path_helper = new \phpbb\path_helper( |
| 146 | new \phpbb\symfony_request( |
| 147 | new phpbb_mock_request() |
| 148 | ), |
| 149 | $this->createMock('\phpbb\request\request'), |
| 150 | $phpbb_root_path, |
| 151 | $phpEx |
| 152 | ); |
| 153 | |
| 154 | $cache_path = $phpbb_root_path . 'cache/twig'; |
| 155 | $context = new \phpbb\template\context(); |
| 156 | $loader = new \phpbb\template\twig\loader(''); |
| 157 | $log = new \phpbb\log\dummy(); |
| 158 | $assets_bag = new \phpbb\template\assets_bag(); |
| 159 | $twig = new \phpbb\template\twig\environment( |
| 160 | $assets_bag, |
| 161 | $config, |
| 162 | $filesystem, |
| 163 | $path_helper, |
| 164 | $cache_path, |
| 165 | $this->extension_manager, |
| 166 | $loader, |
| 167 | new \phpbb\event\dispatcher(), |
| 168 | array( |
| 169 | 'cache' => false, |
| 170 | 'debug' => false, |
| 171 | 'auto_reload' => true, |
| 172 | 'autoescape' => false, |
| 173 | ) |
| 174 | ); |
| 175 | $this->template = new \phpbb\template\twig\twig($path_helper, $config, $context, $twig, $cache_path, $this->user, array(new \phpbb\template\twig\extension($context, $twig, $this->user)), $this->extension_manager); |
| 176 | $twig->setLexer(new \phpbb\template\twig\lexer($twig)); |
| 177 | |
| 178 | $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path)); |
| 179 | } |
| 180 | } |