/** * @param ProductMediaInterface $media */ protected function copyMedia(ProductMediaInterface $media) { $result = $this->mediaManager->copy($media, dirname($this->getPath())); if ($result === true) { $exportPath = $this->mediaManager->getExportPath($media); $this->writtenFiles[sprintf('%s/%s', dirname($this->getPath()), $exportPath)] = $exportPath; } }
/** * Test related method */ public function testCopyMedia() { @mkdir($this->uploadDir, 0777, true); file_put_contents($this->uploadDir . '/phpunit-file.txt', 'Lorem ipsum'); $media = $this->getMediaMock(); $entity = $this->getProductMock('sku000'); $attribute = $this->getAttributeMock('mockFile'); $value = $this->getValueMock($entity, $attribute); $media->expects($this->any())->method('getFilePath')->will($this->returnValue($this->uploadDir . '/phpunit-file.txt')); $media->expects($this->any())->method('getValue')->will($this->returnValue($value)); $media->expects($this->any())->method('getOriginalFilename')->will($this->returnValue('phpunit-file.txt')); $this->assertTrue($this->manager->copy($media, '/tmp/behat/')); $this->assertFileEquals($this->uploadDir . '/phpunit-file.txt', '/tmp/behat/files/sku000/mockFile/phpunit-file.txt'); }