public function testGetException() { $this->setExpectedException('\\Aimeos\\MW\\Media\\Exception'); \Aimeos\MW\Media\Factory::get(null); }
public function uploadItem(\stdClass $params) { $this->checkParams($params, array('site', 'domain')); $this->setLocale($params->site); if (($fileinfo = reset($_FILES)) === false) { throw new \Aimeos\Controller\ExtJS\Exception('No file was uploaded'); } $config = $this->getContext()->getConfig(); /** controller/extjs/media/standard/options * Options used for processing the uploaded media files * * When uploading a file, a preview image for that file is generated if * possible (especially for images). You can configure certain options * for the generated images, namely the quality of those images with * * array( * 'image' => array( * 'jpeg' => array( * 'quality' => 75 * ), * 'png' => array( * 'quality' => 9 * ), * ) * ) * * @param array Multi-dimendional list of configuration options * @since 2014.03 * @category Developer * @category User */ $options = $config->get('controller/extjs/media/standard/options', array()); /** controller/extjs/media/standard/enablecheck * Enables checking uploaded files if they are valid and not part of an attack * * This configuration option is for unit testing only! Please don't disable * the checks for uploaded files in production environments as this * would give attackers the possibility to infiltrate your installation! * * @param boolean True to enable, false to disable * @since 2014.03 * @category Developer */ if ($config->get('controller/extjs/media/standard/enablecheck', true)) { $this->checkFileUpload($fileinfo['tmp_name'], $fileinfo['error']); } $filename = md5($fileinfo['name'] . microtime(true)); $mediaFile = \Aimeos\MW\Media\Factory::get($fileinfo['tmp_name'], $options); $item = $this->getManager()->createItem(); $item->setDomain($params->domain); $item->setLabel(basename($fileinfo['name'])); $item->setMimeType($mediaFile->getMimetype()); if ($mediaFile instanceof \Aimeos\MW\Media\Image\Iface) { $item->setPreview($this->createImage($mediaFile, 'preview', $params->domain, $fileinfo['tmp_name'], $filename)); $item->setUrl($this->createImage($mediaFile, 'files', $params->domain, $fileinfo['tmp_name'], $filename)); } else { $item->setPreview($this->getMimeIcon($mediaFile->getMimetype())); $item->setUrl($this->copyFile($mediaFile, $params->domain, $filename)); } if (unlink($fileinfo['tmp_name']) === false) { $msg = sprintf('Deleting file "%1$s" failed', $fileinfo['tmp_name']); $this->getContext()->getLogger()->log($msg, \Aimeos\MW\Logger\Base::WARN); } return (object) $item->toArray(); }
public function testStoreImage() { $fsm = $this->getMockBuilder('\\Aimeos\\MW\\Filesystem\\Manager\\Standard')->setMethods(array('get'))->disableOriginalConstructor()->getMock(); $fs = $this->getMockBuilder('\\Aimeos\\MW\\Filesystem\\Standard')->setMethods(array('writef'))->disableOriginalConstructor()->getMock(); $fsm->expects($this->once())->method('get')->will($this->returnValue($fs)); $fs->expects($this->once())->method('writef'); $this->context->setFilesystemManager($fsm); $dest = dirname(dirname(dirname(__DIR__))) . '/tmp/'; if (!is_dir($dest)) { mkdir($dest, 0755, true); } copy(__DIR__ . '/testfiles/test.gif', $dest . 'test.gif'); $file = \Aimeos\MW\Media\Factory::get($dest . 'test.gif'); $result = $this->access('storeImage')->invokeArgs($this->object, array($file, 'files', 'test', 'fs-media')); $this->assertEquals('files/t/e/test.gif', $result); }
/** * Returns the media object for the given file name * * @param string $filename Path and name to the file * @return \Aimeos\MW\Media\Iface Media object */ protected function getMediaFile($filename) { /** controller/common/media/standard/options * Options used for processing the uploaded media files * * When uploading a file, a preview image for that file is generated if * possible (especially for images). You can configure certain options * for the generated images, namely the quality of those images with * * array( * 'image' => array( * 'jpeg' => array( * 'quality' => 75 * ), * 'png' => array( * 'quality' => 9 * ), * ) * ) * * @param array Multi-dimendional list of configuration options * @since 2016.01 * @category Developer * @category User */ $options = $this->context->getConfig()->get('controller/common/media/standard/options', array()); return \Aimeos\MW\Media\Factory::get($filename, $options); }