/** * Process sizes * * @param string $file File data * @param string $fileName File name * @param string $context File context * @param string $extension File extension * @param FilesystemAdapter $filesystemAdapter * * @return Processor */ public function processSizes($file, $fileName, $context, $extension, FilesystemAdapter $filesystemAdapter) { foreach ($this->config[$context] as $sizeName => $values) { $image = $this->openImageHandler->loadImage($file); $operation = $this->manipulatorFactory->create($values['operation']); $image = $operation->manipulate($image, $values['width'], $values['height']); $this->fileManager->setFileSystemAdapter($filesystemAdapter)->uploadFile($image, $extension, $context, $sizeName, $fileName); } return $this; }
/** * Test file upload with correct data */ public function testUploadFileWithCorrectData() { $context = 'test'; $size = 'default'; $this->fileManager->setFileSystemAdapter($this->filesystemAdapter); $fileName1 = $this->fileManager->uploadFile($this->file, 'png', $context); $uploadedFile = file_get_contents($this->rootPath . "{$context}/" . $fileName1); static::assertEquals($uploadedFile, $this->file); $fileName2 = $this->fileManager->uploadFile($this->file, 'png', $context, $size); $uploadedFile = file_get_contents($this->rootPath . "{$context}/{$size}/" . $fileName2); static::assertEquals($uploadedFile, $this->file); $this->fileManager->uploadFile($this->file, 'png', $context, $size, 'test_image.png'); $uploadedFile = file_get_contents($this->rootPath . "{$context}/{$size}/test_image.png"); static::assertEquals($uploadedFile, $this->file); unlink($this->rootPath . "{$context}/" . $fileName1); unlink($this->rootPath . "{$context}/{$size}/" . $fileName2); unlink($this->rootPath . "{$context}/{$size}/test_image.png"); rmdir($this->rootPath . "{$context}/{$size}/"); rmdir($this->rootPath . "{$context}/"); }