From 53008c87828746c316019e758641a2a4e37f522b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 9 Oct 2015 12:14:19 +0200 Subject: [ticket/14168] Fix tabs in manager and add test file PHPBB3-14168 --- tests/attachment/manager_test.php | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/attachment/manager_test.php (limited to 'tests/attachment/manager_test.php') diff --git a/tests/attachment/manager_test.php b/tests/attachment/manager_test.php new file mode 100644 index 0000000000..f71ccfbb6c --- /dev/null +++ b/tests/attachment/manager_test.php @@ -0,0 +1,69 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +class phpbb_attachment_manager_test extends \phpbb_test_case +{ + protected $delete; + protected $resync; + protected $upload; + + public function setUp() + { + $this->delete = $this->getMockBuilder('\phpbb\attachment\delete') + ->disableOriginalConstructor() + ->setMethods(['delete', 'unlink']) + ->getMock(); + $this->resync = $this->getMockBuilder('\phpbb\attachment\resync') + ->disableOriginalConstructor() + ->setMethods(['resync']) + ->getMock(); + $this->upload = $this->getMockBuilder('\phpbb\attachment\upload') + ->disableOriginalConstructor() + ->setMethods(['upload']) + ->getMock(); + } + + protected function get_manager() + { + return new \phpbb\attachment\manager($this->delete, $this->resync, $this->upload); + } + + public function data_delete() + { + return array( + [ + ['foo', [1, 2, 3], false], + ['foo', [1, 2, 3], false], + true, + ], + [ + ['foo', [1, 2, 3], true], + ['foo', [1, 2, 3]], + true, + ], + ); + } + + /** + * @dataProvider data_delete + */ + public function test_delete($input, $input_manager, $output) + { + $mock = $this->delete->expects($this->atLeastOnce()) + ->method('delete'); + $mock = call_user_func_array([$mock, 'with'], $input); + $mock->willReturn($output); + $manager = $this->get_manager(); + $this->assertSame($output, call_user_func_array([$manager, 'delete'], $input_manager)); + } +} -- cgit v1.2.1 From b90783a296bc15427e9f29a5ed4d0912afcfa6b4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 9 Oct 2015 12:29:00 +0200 Subject: [ticket/14168] Add new test method and more tests One test method to rule them all. PHPBB3-14168 --- tests/attachment/manager_test.php | 45 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'tests/attachment/manager_test.php') diff --git a/tests/attachment/manager_test.php b/tests/attachment/manager_test.php index f71ccfbb6c..85a6465ab9 100644 --- a/tests/attachment/manager_test.php +++ b/tests/attachment/manager_test.php @@ -21,7 +21,7 @@ class phpbb_attachment_manager_test extends \phpbb_test_case { $this->delete = $this->getMockBuilder('\phpbb\attachment\delete') ->disableOriginalConstructor() - ->setMethods(['delete', 'unlink']) + ->setMethods(['delete', 'unlink_attachment']) ->getMock(); $this->resync = $this->getMockBuilder('\phpbb\attachment\resync') ->disableOriginalConstructor() @@ -66,4 +66,47 @@ class phpbb_attachment_manager_test extends \phpbb_test_case $manager = $this->get_manager(); $this->assertSame($output, call_user_func_array([$manager, 'delete'], $input_manager)); } + + public function data_manager() + { + return array( + array( + 'delete', + 'unlink_attachment', + 'unlink', + ['foo'], + ['foo', 'file', false], + true, + ), + array( + 'delete', + 'unlink_attachment', + 'unlink', + ['foo', 'bar'], + ['foo', 'bar', false], + true, + ), + array( + 'delete', + 'unlink_attachment', + 'unlink', + ['foo', 'bar', true], + ['foo', 'bar', true], + true, + ), + ); + } + + /** + * @dataProvider data_manager + */ + public function test_manager($class, $method_class, $method_manager, $input_manager, $input_method, $output) + { + $mock = call_user_func_array([$this->{$class}, 'expects'], [$this->atLeastOnce()]); + $mock = $mock->method($method_class); + $mock = call_user_func_array([$mock, 'with'], $input_method); + $mock->willReturn($output); + $manager = $this->get_manager(); + $this->assertSame($output, call_user_func_array([$manager, $method_manager], $input_manager)); + } } -- cgit v1.2.1 From 52dccd3dba0808e4e19aa8407da1d4c75fe241cd Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 9 Oct 2015 14:33:12 +0200 Subject: [ticket/14168] Add more test cases for attachment manager PHPBB3-14168 --- tests/attachment/manager_test.php | 81 ++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 31 deletions(-) (limited to 'tests/attachment/manager_test.php') diff --git a/tests/attachment/manager_test.php b/tests/attachment/manager_test.php index 85a6465ab9..01a6049602 100644 --- a/tests/attachment/manager_test.php +++ b/tests/attachment/manager_test.php @@ -38,35 +38,6 @@ class phpbb_attachment_manager_test extends \phpbb_test_case return new \phpbb\attachment\manager($this->delete, $this->resync, $this->upload); } - public function data_delete() - { - return array( - [ - ['foo', [1, 2, 3], false], - ['foo', [1, 2, 3], false], - true, - ], - [ - ['foo', [1, 2, 3], true], - ['foo', [1, 2, 3]], - true, - ], - ); - } - - /** - * @dataProvider data_delete - */ - public function test_delete($input, $input_manager, $output) - { - $mock = $this->delete->expects($this->atLeastOnce()) - ->method('delete'); - $mock = call_user_func_array([$mock, 'with'], $input); - $mock->willReturn($output); - $manager = $this->get_manager(); - $this->assertSame($output, call_user_func_array([$manager, 'delete'], $input_manager)); - } - public function data_manager() { return array( @@ -77,6 +48,7 @@ class phpbb_attachment_manager_test extends \phpbb_test_case ['foo'], ['foo', 'file', false], true, + true, ), array( 'delete', @@ -85,6 +57,7 @@ class phpbb_attachment_manager_test extends \phpbb_test_case ['foo', 'bar'], ['foo', 'bar', false], true, + true, ), array( 'delete', @@ -93,6 +66,52 @@ class phpbb_attachment_manager_test extends \phpbb_test_case ['foo', 'bar', true], ['foo', 'bar', true], true, + true, + ), + array( + 'delete', + 'delete', + 'delete', + ['foo', [1, 2, 3]], + ['foo', [1, 2, 3], true], + true, + true, + ), + array( + 'delete', + 'delete', + 'delete', + ['foo', [1, 2, 3], false], + ['foo', [1, 2, 3], false], + true, + true, + ), + array( + 'resync', + 'resync', + 'resync', + ['foo', [1, 2, 3]], + ['foo', [1, 2, 3]], + true, + null, + ), + array( + 'upload', + 'upload', + 'upload', + ['foo', 1], + ['foo', 1, false, '', false, []], + true, + true, + ), + array( + 'upload', + 'upload', + 'upload', + ['foo', 1, true, 'bar', true, ['filename' => 'foobar']], + ['foo', 1, true, 'bar', true, ['filename' => 'foobar']], + true, + true, ), ); } @@ -100,12 +119,12 @@ class phpbb_attachment_manager_test extends \phpbb_test_case /** * @dataProvider data_manager */ - public function test_manager($class, $method_class, $method_manager, $input_manager, $input_method, $output) + public function test_manager($class, $method_class, $method_manager, $input_manager, $input_method, $return, $output) { $mock = call_user_func_array([$this->{$class}, 'expects'], [$this->atLeastOnce()]); $mock = $mock->method($method_class); $mock = call_user_func_array([$mock, 'with'], $input_method); - $mock->willReturn($output); + $mock->willReturn($return); $manager = $this->get_manager(); $this->assertSame($output, call_user_func_array([$manager, $method_manager], $input_manager)); } -- cgit v1.2.1 From 49312f05f88ca58346cbb00c2f03f01fd2a3d56d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 12 Oct 2015 11:34:11 +0200 Subject: [ticket/14168] Use attachment manager instead of separate classes PHPBB3-14168 --- tests/attachment/manager_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/attachment/manager_test.php') diff --git a/tests/attachment/manager_test.php b/tests/attachment/manager_test.php index 01a6049602..47d7f38b1d 100644 --- a/tests/attachment/manager_test.php +++ b/tests/attachment/manager_test.php @@ -74,8 +74,8 @@ class phpbb_attachment_manager_test extends \phpbb_test_case 'delete', ['foo', [1, 2, 3]], ['foo', [1, 2, 3], true], - true, - true, + 5, + 5, ), array( 'delete', @@ -83,8 +83,8 @@ class phpbb_attachment_manager_test extends \phpbb_test_case 'delete', ['foo', [1, 2, 3], false], ['foo', [1, 2, 3], false], - true, - true, + 2, + 2, ), array( 'resync', -- cgit v1.2.1