Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
70 / 70 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_cron_wrapper_test | |
100.00% |
70 / 70 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| test_generate_template_pagination | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
| test_is_parametrized_false | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_is_ready | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_url_non_parametrized | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_html_tag | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| test_call_forwards_to_task | |
100.00% |
17 / 17 |
|
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__ . '/../template/template_test_case.php'; |
| 15 | |
| 16 | class phpbb_cron_wrapper_test extends phpbb_template_template_test_case |
| 17 | { |
| 18 | private $task; |
| 19 | private $routing_helper; |
| 20 | private $wrapper; |
| 21 | |
| 22 | protected function setUp(): void |
| 23 | { |
| 24 | global $phpbb_root_path; |
| 25 | |
| 26 | $this->setup_engine([], $phpbb_root_path . 'styles/all/template'); |
| 27 | |
| 28 | global $phpbb_filesystem; |
| 29 | |
| 30 | $phpbb_filesystem = new \phpbb\filesystem\filesystem(); |
| 31 | |
| 32 | $this->task = $this->createMock(\phpbb\cron\task\task::class); |
| 33 | $this->routing_helper = $this->createMock(\phpbb\routing\helper::class); |
| 34 | |
| 35 | $this->wrapper = new \phpbb\cron\task\wrapper( |
| 36 | $this->task, |
| 37 | $this->routing_helper, |
| 38 | $this->template |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | public function test_generate_template_pagination() |
| 43 | { |
| 44 | $this->task = $this->createMock(\phpbb\cron\task\parametrized::class); |
| 45 | $this->task->expects($this->any()) |
| 46 | ->method('get_parameters') |
| 47 | ->willReturn(['f' => '5']); |
| 48 | $this->task->expects($this->any()) |
| 49 | ->method('get_name') |
| 50 | ->willReturn('test_task'); |
| 51 | $this->routing_helper = $this->createMock(\phpbb\routing\helper::class); |
| 52 | $this->routing_helper->expects($this->any()) |
| 53 | ->method('route') |
| 54 | ->with('phpbb_cron_run', ['cron_type' => 'test_task', 'f' => '5']) |
| 55 | ->willReturn('app.php/cron/foo?f=5'); |
| 56 | |
| 57 | $this->wrapper = new \phpbb\cron\task\wrapper( |
| 58 | $this->task, |
| 59 | $this->routing_helper, |
| 60 | $this->template |
| 61 | ); |
| 62 | |
| 63 | $this->assertEquals('<img class="sr-only" aria-hidden="true" src="app.php/cron/foo?f=5" width="1" height="1" alt="">', str_replace(["\n", "\t"], '', $this->wrapper->get_html_tag())); |
| 64 | } |
| 65 | |
| 66 | public function test_is_parametrized_false() |
| 67 | { |
| 68 | $this->assertFalse($this->wrapper->is_parametrized()); |
| 69 | } |
| 70 | |
| 71 | public function test_is_ready() |
| 72 | { |
| 73 | $this->task->method('is_runnable')->willReturn(true); |
| 74 | $this->task->method('should_run')->willReturn(true); |
| 75 | |
| 76 | $this->assertTrue($this->wrapper->is_ready()); |
| 77 | } |
| 78 | |
| 79 | public function test_get_url_non_parametrized() |
| 80 | { |
| 81 | $this->task->method('get_name')->willReturn('test_task'); |
| 82 | $this->routing_helper->expects($this->once()) |
| 83 | ->method('route') |
| 84 | ->with('phpbb_cron_run', ['cron_type' => 'test_task']) |
| 85 | ->willReturn('/cron/url'); |
| 86 | |
| 87 | $this->assertEquals('/cron/url', $this->wrapper->get_url()); |
| 88 | } |
| 89 | |
| 90 | public function test_get_html_tag() |
| 91 | { |
| 92 | $this->template = $this->createMock(\phpbb\template\template::class); |
| 93 | $this->wrapper = new \phpbb\cron\task\wrapper( |
| 94 | $this->task, |
| 95 | $this->routing_helper, |
| 96 | $this->template |
| 97 | ); |
| 98 | |
| 99 | $this->template->expects($this->once()) |
| 100 | ->method('set_filenames'); |
| 101 | $this->template->expects($this->once()) |
| 102 | ->method('assign_var'); |
| 103 | $this->template->expects($this->once()) |
| 104 | ->method('assign_display') |
| 105 | ->willReturn('<img src="cron">'); |
| 106 | |
| 107 | $this->assertEquals('<img src="cron">', $this->wrapper->get_html_tag()); |
| 108 | } |
| 109 | |
| 110 | public function test_call_forwards_to_task() |
| 111 | { |
| 112 | $this->task = $this->getMockBuilder(\phpbb\cron\task\task::class) |
| 113 | ->disableOriginalConstructor() |
| 114 | ->onlyMethods(['get_name', 'run', 'is_runnable', 'should_run']) |
| 115 | ->addMethods(['some_method']) |
| 116 | ->getMock(); |
| 117 | $this->routing_helper = $this->createMock(\phpbb\routing\helper::class); |
| 118 | |
| 119 | $this->wrapper = new \phpbb\cron\task\wrapper( |
| 120 | $this->task, |
| 121 | $this->routing_helper, |
| 122 | $this->template |
| 123 | ); |
| 124 | $this->task->expects($this->once()) |
| 125 | ->method('some_method') |
| 126 | ->with('arg1', 'arg2') |
| 127 | ->willReturn('result'); |
| 128 | |
| 129 | $result = $this->wrapper->some_method('arg1', 'arg2'); |
| 130 | $this->assertEquals('result', $result); |
| 131 | } |
| 132 | } |