public function test_upload_wrong_path() { $type_remote = new \phpbb\files\types\foo($this->config, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_remote->set_upload($upload); $type_remote::$tempnam_path = $this->phpbb_root_path . 'cache/wrong/path'; $file = $type_remote->upload('http://google.com/?.png'); $this->assertSame(array('NOT_UPLOADED'), $file->error); $type_remote::$tempnam_path = ''; }
/** * @dataProvider data_upload_form */ public function test_upload_form($filename, $upload_ary, $expected) { $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, new \phpbb\mimetype\guesser(array('mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser()))); $filespec_local = new ReflectionProperty($filespec, 'local'); $filespec_local->setAccessible(true); $filespec_local->setValue($filespec, true); $this->container->set('files.filespec', $filespec); $this->factory = new \phpbb\files\factory($this->container); $type_local = new \phpbb\files\types\local($this->factory, $this->language, $this->php_ini, $this->request); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_local->set_upload($upload); $file = $type_local->upload($filename, $upload_ary); $this->assertSame($expected, $file->error); $this->assertInstanceOf('\\phpbb\\files\\filespec', $file); }
/** * @dataProvider data_upload_form */ public function test_upload_form($upload, $expected, $plupload = array()) { $this->request = $this->getMock('\\phpbb\\request\\request'); $this->request->expects($this->any())->method('file')->willReturn($upload); $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path, new \phpbb\mimetype\guesser(array('mimetype.extension_guesser' => new \phpbb\mimetype\extension_guesser()))); $this->container->set('files.filespec', $filespec); $this->factory = new \phpbb\files\factory($this->container); $this->plupload = $this->getMockBuilder('\\phpbb\\plupload\\plupload')->disableOriginalConstructor()->getMock(); $this->plupload->expects($this->any())->method('handle_upload')->willReturn($plupload); $type_form = new \phpbb\files\types\form($this->factory, $this->language, $this->php_ini, $this->plupload, $this->request); $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_form->set_upload($upload); $file = $type_form->upload('foobar'); $this->assertSame($expected, $file->error); $this->assertInstanceOf('\\phpbb\\files\\filespec', $file); }
/** * @dataProvider data_internal_error */ public function test_assign_internal_error($error_code, $expected) { $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $this->assertSame($expected, $upload->assign_internal_error($error_code)); }
public function test_valid_dimensions() { $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(false)->set_max_filesize(false)->set_allowed_dimensions(1, 1, 100, 100); $file1 = $this->gen_valid_filespec(); $file2 = $this->gen_valid_filespec(); $file2->height = 101; $file3 = $this->gen_valid_filespec(); $file3->width = 0; $this->assertTrue($upload->valid_dimensions($file1)); $this->assertFalse($upload->valid_dimensions($file2)); $this->assertFalse($upload->valid_dimensions($file3)); }
public function test_too_large() { /** @var \phpbb\files\upload $upload */ $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('')->set_allowed_extensions(array('gif'))->set_max_filesize(100); $file = $upload->handle_upload('files.types.remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(1, sizeof($file->error)); $this->assertEquals('WRONG_FILESIZE', $file->error[0]); }