Skip to content

Commit 5d35d50

Browse files
committed
Fix tests
1 parent 23dd8f1 commit 5d35d50

File tree

6 files changed

+32
-97
lines changed

6 files changed

+32
-97
lines changed

migrations/v30x/m1_storage.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ public function migrate_ads_storage()
5656
/** @var file_tracker $file_tracker */
5757
$file_tracker = $this->container->get('storage.file_tracker');
5858

59-
if (!$filesystem->exists($this->phpbb_root_path . 'images/phpbb_ads'))
59+
$dir = $this->phpbb_root_path . 'images/phpbb_ads';
60+
61+
if (!$filesystem->exists($dir))
6062
{
61-
$filesystem->mkdir($this->phpbb_root_path . 'images/phpbb_ads');
63+
$filesystem->mkdir($dir);
6264
}
6365

64-
$dir = $this->phpbb_root_path . 'images/phpbb_ads';
6566
$handle = @opendir($dir);
6667

6768
if ($handle)
@@ -73,7 +74,7 @@ public function migrate_ads_storage()
7374
continue;
7475
}
7576

76-
$file_tracker->track_file('phpbb_ads', $file, filesize($this->phpbb_root_path . 'images/phpbb_ads/' . $file));
77+
$file_tracker->track_file('phpbb_ads', $file, filesize($dir . '/' . $file));
7778
}
7879

7980
closedir($handle);

tests/banner/banner_base.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ class banner_base extends \phpbb_test_case
1515
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\files\upload */
1616
protected $files_upload;
1717

18-
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\filesystem\filesystem */
19-
protected $filesystem;
18+
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\files\filespec_storage */
19+
protected $file;
2020

21-
/** @var string */
22-
protected $root_path;
21+
/** @var \phpbb\storage\storage */
2322

24-
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\files\filespec */
25-
protected $file;
23+
protected $storage;
2624

2725
protected static function setup_extensions()
2826
{
@@ -36,16 +34,12 @@ protected function setUp(): void
3634
{
3735
parent::setUp();
3836

39-
global $phpbb_root_path;
40-
4137
$this->files_upload = $this->getMockBuilder('\phpbb\files\upload')
4238
->disableOriginalConstructor()
4339
->getMock();
44-
$this->filesystem = $this->getMockBuilder('\phpbb\filesystem\filesystem')
40+
$this->storage = $this->getMockBuilder('\phpbb\storage\storage')
4541
->disableOriginalConstructor()
4642
->getMock();
47-
48-
$this->root_path = $phpbb_root_path;
4943
}
5044

5145
/**
@@ -57,8 +51,7 @@ public function get_manager()
5751
{
5852
return new \phpbb\ads\banner\banner(
5953
$this->files_upload,
60-
$this->filesystem,
61-
$this->root_path
54+
$this->storage
6255
);
6356
}
6457
}

tests/banner/create_storage_dir_test.php

-61
This file was deleted.

tests/banner/remove_test.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ public function test_remove()
2020
$manager = $this->get_manager();
2121

2222
// Mock filespec
23-
$file = $this->getMockBuilder('\phpbb\files\filespec')
23+
$file = $this->getMockBuilder('\phpbb\files\filespec_storage')
2424
->disableOriginalConstructor()
2525
->getMock();
2626
$manager->set_file($file);
2727

2828
$file->expects(self::once())
29-
->method('remove');
29+
->method('remove')
30+
->with($this->storage);
3031

3132
$manager->remove();
3233
}

tests/banner/upload_test.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function test_upload($file_move_success)
4242
->with(array('gif', 'jpg', 'jpeg', 'png'));
4343

4444
// Mock filespec
45-
$file = $this->getMockBuilder('\phpbb\files\filespec')
45+
$file = $this->getMockBuilder('\phpbb\files\filespec_storage')
4646
->disableOriginalConstructor()
4747
->getMock();
4848
if (!$file_move_success)
@@ -52,7 +52,7 @@ public function test_upload($file_move_success)
5252

5353
$this->files_upload->expects(self::once())
5454
->method('handle_upload')
55-
->with('files.types.form', 'banner')
55+
->with('files.types.form_storage', 'banner')
5656
->willReturn($file);
5757

5858
$file->expects(self::once())
@@ -61,7 +61,7 @@ public function test_upload($file_move_success)
6161

6262
$file->expects(self::once())
6363
->method('move_file')
64-
->with('images/phpbb_ads')
64+
->with($this->storage)
6565
->willReturn($file_move_success);
6666

6767
if (!$file_move_success)

tests/controller/admin_input_test.php

+15-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class admin_input_test extends \phpbb_database_test_case
1515
/** @var bool A return value for check_form_key() */
1616
public static $valid_form = true;
1717

18+
/** @var \phpbb\controller\helper */
19+
protected $controller_helper;
20+
1821
/** @var \phpbb\user */
1922
protected $user;
2023

@@ -60,6 +63,9 @@ protected function setUp(): void
6063

6164
// Load/Mock classes required by the controller class
6265
$this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
66+
$this->controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
67+
->disableOriginalConstructor()
68+
->getMock();
6369
$this->user = $user = new \phpbb\user($this->language, '\phpbb\datetime');
6470
$this->user->timezone = new \DateTimeZone('UTC');
6571
$avatar_helper = $this->getMockBuilder('\phpbb\avatar\helper')
@@ -92,6 +98,7 @@ protected function setUp(): void
9298
public function get_input_controller()
9399
{
94100
$input = new \phpbb\ads\controller\admin_input(
101+
$this->controller_helper,
95102
$this->user,
96103
$this->user_loader,
97104
$this->language,
@@ -210,24 +217,15 @@ public function test_banner_upload($can_create_directory, $can_move_file, $is_aj
210217
{
211218
$input_controller = $this->get_input_controller();
212219

213-
$create_storage_dir = $this->banner->expects(self::once())
214-
->method('create_storage_dir');
215-
if (!$can_create_directory)
220+
$upload = $this->banner->expects(self::once())
221+
->method('upload');
222+
if (!$can_move_file)
216223
{
217-
$create_storage_dir->willThrowException(new \phpbb\exception\runtime_exception('CANNOT_CREATE_DIRECTORY'));
224+
$upload->willThrowException(new \phpbb\exception\runtime_exception('FILE_MOVE_UNSUCCESSFUL'));
218225
}
219226
else
220227
{
221-
$upload = $this->banner->expects(self::once())
222-
->method('upload');
223-
if (!$can_move_file)
224-
{
225-
$upload->willThrowException(new \phpbb\exception\runtime_exception('FILE_MOVE_UNSUCCESSFUL'));
226-
}
227-
else
228-
{
229-
$upload->willReturn('abcdef.jpg');
230-
}
228+
$upload->willReturn('abcdef.jpg');
231229
}
232230

233231
if (!$can_create_directory || !$can_move_file)
@@ -236,6 +234,9 @@ public function test_banner_upload($can_create_directory, $can_move_file, $is_aj
236234
->method('remove');
237235
}
238236

237+
$this->controller_helper->method('route')
238+
->willReturn('/images/phpbb_ads/abcdef.jpg');
239+
239240
$this->request->expects(self::once())
240241
->method('is_ajax')
241242
->willReturn($is_ajax);

0 commit comments

Comments
 (0)