Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
13 / 39 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_text_processing_tickets_test | |
33.33% |
13 / 39 |
|
50.00% |
1 / 2 |
26.96 | |
0.00% |
0 / 1 |
| test_tickets | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
3 | |||
| get_tickets_data | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
30 | |||
| 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 | class phpbb_text_processing_tickets_test extends phpbb_test_case |
| 15 | { |
| 16 | /** |
| 17 | * @dataProvider get_tickets_data |
| 18 | */ |
| 19 | public function test_tickets($ticket_id, $original, $expected, $fixture, $before_assert, $after_assert) |
| 20 | { |
| 21 | global $phpbb_container; |
| 22 | |
| 23 | $phpbb_container = new phpbb_mock_container_builder; |
| 24 | |
| 25 | $this->get_test_case_helpers()->set_s9e_services($phpbb_container, $fixture); |
| 26 | |
| 27 | $parser = $phpbb_container->get('text_formatter.parser'); |
| 28 | $renderer = $phpbb_container->get('text_formatter.renderer'); |
| 29 | |
| 30 | if (isset($before_assert)) |
| 31 | { |
| 32 | $test = $this; |
| 33 | $before_assert(get_defined_vars()); |
| 34 | } |
| 35 | |
| 36 | $parsed_text = $parser->parse($original); |
| 37 | |
| 38 | $this->assertSame($expected, $renderer->render($parsed_text)); |
| 39 | |
| 40 | if (isset($after_assert)) |
| 41 | { |
| 42 | $test = $this; |
| 43 | $after_assert(get_defined_vars()); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public static function get_tickets_data() |
| 48 | { |
| 49 | $tests = array(); |
| 50 | |
| 51 | foreach (glob(__DIR__ . '/tickets_data/*.txt') as $txt_filename) |
| 52 | { |
| 53 | $ticket_id = basename($txt_filename, '.txt'); |
| 54 | $html_filename = substr($txt_filename, 0, -3) . 'html'; |
| 55 | $xml_filename = substr($txt_filename, 0, -3) . 'xml'; |
| 56 | $before_filename = substr($txt_filename, 0, -3) . 'before.php'; |
| 57 | $after_filename = substr($txt_filename, 0, -3) . 'after.php'; |
| 58 | |
| 59 | if (!file_exists($xml_filename)) |
| 60 | { |
| 61 | $xml_filename = __DIR__ . '/../fixtures/empty.xml'; |
| 62 | } |
| 63 | |
| 64 | $before_assert = null; |
| 65 | if (file_exists($before_filename)) |
| 66 | { |
| 67 | include($before_filename); |
| 68 | $before_assert = 'before_assert_' . strtolower(str_replace('-', '_', $ticket_id)); |
| 69 | } |
| 70 | |
| 71 | $after_assert = null; |
| 72 | if (file_exists($after_filename)) |
| 73 | { |
| 74 | include($after_filename); |
| 75 | $after_assert = 'after_assert_' . strtolower(str_replace('-', '_', $ticket_id)); |
| 76 | } |
| 77 | |
| 78 | $tests[] = array( |
| 79 | $ticket_id, |
| 80 | file_get_contents($txt_filename), |
| 81 | file_get_contents($html_filename), |
| 82 | $xml_filename, |
| 83 | $before_assert, |
| 84 | $after_assert |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | return $tests; |
| 89 | } |
| 90 | } |