public function test_common_checks_disallowed_content() { $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('jpg'))->set_max_filesize(1000); $file = new \phpbb\files\filespec($this->filesystem, $this->language, $this->php_ini, new \FastImageSize\FastImageSize(), $this->phpbb_root_path); $file->set_upload_ary(array('size' => 50, 'tmp_name' => dirname(__FILE__) . '/fixture/disallowed', 'name' => 'disallowed.jpg', 'type' => 'image/jpg'))->set_upload_namespace($upload); file_put_contents(dirname(__FILE__) . '/fixture/disallowed', '<body>' . file_get_contents(dirname(__FILE__) . '/fixture/jpg')); $upload->common_checks($file); $this->assertEquals('DISALLOWED_CONTENT', $file->error[0]); unlink(dirname(__FILE__) . '/fixture/disallowed'); }
/** * @dataProvider data_move_file_imagesize */ public function test_move_file_imagesize($imagesize_return, $expected_error) { // Initialise a blank filespec object for use with trivial methods $upload_ary = array('name' => 'gif_moved', 'type' => 'image/gif', 'size' => '', 'tmp_name' => $this->path . 'copies/gif_copy', 'error' => ''); $imagesize = $this->getMockBuilder('\\FastImageSize\\FastImageSize')->getMock(); $imagesize->expects($this->any())->method('getImageSize')->with($this->anything())->willReturn($imagesize_return); $upload = new phpbb_mock_fileupload(); $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; $filespec = new \phpbb\files\filespec($this->filesystem, $this->language, new \bantu\IniGetWrapper\IniGetWrapper(), $imagesize, '', $this->mimetype_guesser); $filespec->set_upload_ary($upload_ary); $this->set_reflection_property($filespec, 'local', false); $this->set_reflection_property($filespec, 'extension', 'gif'); $filespec->set_upload_namespace($upload); $this->assertEquals(true, $filespec->move_file($this->path . 'copies')); $this->assertEquals($filespec->get('file_moved'), file_exists($this->path . 'copies/gif_moved')); $this->assertSame($expected_error, $filespec->error); }