Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
57 / 57 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_text_reparser_manager_test | |
100.00% |
57 / 57 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_resume_data | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| test_update_resume_data | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
1 | |||
| test_schedule | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_schedule_all | |
100.00% |
4 / 4 |
|
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 | |
| 14 | require_once __DIR__ . '/../mock/container_builder.php'; |
| 15 | require_once __DIR__ . '/../test_framework/phpbb_database_test_case.php'; |
| 16 | |
| 17 | class phpbb_text_reparser_manager_test extends phpbb_database_test_case |
| 18 | { |
| 19 | /** @var \phpbb\config\config */ |
| 20 | protected $config; |
| 21 | |
| 22 | /** @var \phpbb\config\db_text */ |
| 23 | protected $config_text; |
| 24 | |
| 25 | /** @var \phpbb\textreparser\manager */ |
| 26 | protected $reparser_manager; |
| 27 | |
| 28 | public function getDataSet() |
| 29 | { |
| 30 | return $this->createXMLDataSet(__DIR__ . '/fixtures/config_text.xml'); |
| 31 | } |
| 32 | |
| 33 | protected function setUp(): void |
| 34 | { |
| 35 | parent::setUp(); |
| 36 | |
| 37 | $this->config = new \phpbb\config\config(array( |
| 38 | 'test_reparser_cron_interval' => 0, |
| 39 | 'my_reparser_cron_interval' => 100, |
| 40 | )); |
| 41 | |
| 42 | $db = $this->new_dbal(); |
| 43 | $this->config_text = new \phpbb\config\db_text($db, 'phpbb_config_text'); |
| 44 | |
| 45 | $service_collection = new \phpbb\di\service_collection(new phpbb_mock_container_builder()); |
| 46 | $service_collection->add('test_reparser'); |
| 47 | $service_collection->add('another_reparser'); |
| 48 | $service_collection->add('my_reparser'); |
| 49 | |
| 50 | $this->reparser_manager = new \phpbb\textreparser\manager($this->config, $this->config_text, $service_collection); |
| 51 | } |
| 52 | |
| 53 | public function test_get_resume_data() |
| 54 | { |
| 55 | $resume_data = array( |
| 56 | 'test_reparser' => array( |
| 57 | 'range-min' => 0, |
| 58 | 'range-max' => 100, |
| 59 | 'range-size' => 50, |
| 60 | ), |
| 61 | ); |
| 62 | $this->config_text->set('reparser_resume', serialize($resume_data)); |
| 63 | |
| 64 | $this->assert_array_content_equals($resume_data['test_reparser'], $this->reparser_manager->get_resume_data('test_reparser')); |
| 65 | $this->assertEmpty($this->reparser_manager->get_resume_data('another_reparser')); |
| 66 | } |
| 67 | |
| 68 | public function test_update_resume_data() |
| 69 | { |
| 70 | $resume_data = array( |
| 71 | 'test_reparser' => array( |
| 72 | 'range-min' => 0, |
| 73 | 'range-max' => 100, |
| 74 | 'range-size' => 50, |
| 75 | ), |
| 76 | ); |
| 77 | $this->config_text->set('reparser_resume', serialize($resume_data)); |
| 78 | |
| 79 | $this->reparser_manager->update_resume_data('another_reparser', 5, 20, 10, false); |
| 80 | $this->assert_array_content_equals($resume_data, unserialize($this->config_text->get('reparser_resume'))); |
| 81 | |
| 82 | $this->reparser_manager->update_resume_data('test_reparser', 0, 50, 50); |
| 83 | $resume_data = array( |
| 84 | 'test_reparser' => array( |
| 85 | 'range-min' => 0, |
| 86 | 'range-max' => 50, |
| 87 | 'range-size' => 50, |
| 88 | ), |
| 89 | 'another_reparser' => array( |
| 90 | 'range-min' => 5, |
| 91 | 'range-max' => 20, |
| 92 | 'range-size' => 10, |
| 93 | ), |
| 94 | ); |
| 95 | $this->assert_array_content_equals($resume_data, unserialize($this->config_text->get('reparser_resume'))); |
| 96 | } |
| 97 | |
| 98 | public function test_schedule() |
| 99 | { |
| 100 | $this->reparser_manager->schedule('no_reparser', 21); |
| 101 | $this->assertArrayNotHasKey('no_reparser_cron_interval', $this->config); |
| 102 | |
| 103 | $this->reparser_manager->schedule('another_reparser', 42); |
| 104 | $this->assertArrayNotHasKey('another_reparser_cron_interval', $this->config); |
| 105 | |
| 106 | $this->reparser_manager->schedule('test_reparser', 20); |
| 107 | $this->assertEquals(20, $this->config['test_reparser_cron_interval']); |
| 108 | } |
| 109 | |
| 110 | public function test_schedule_all() |
| 111 | { |
| 112 | $this->reparser_manager->schedule_all(180); |
| 113 | $this->assertEquals(180, $this->config['test_reparser_cron_interval']); |
| 114 | $this->assertEquals(180, $this->config['my_reparser_cron_interval']); |
| 115 | $this->assertArrayNotHasKey('another_reparser_cron_interval', $this->config); |
| 116 | } |
| 117 | } |