public function getTestData()
 {
     $correctEntity = new TestAttachment();
     $correctEntity->setId(1);
     $correctEntity->setFilename('test.doc');
     $incorrectEntity = new File();
     return ['correctEntity' => [$correctEntity, true], 'incorrectEntity' => [$incorrectEntity, false]];
 }
 public function testGetFilteredImageUrl()
 {
     $this->attachment->setId(1);
     $filerName = 'testFilter';
     $this->attachment->setOriginalFilename('test.doc');
     $this->router->expects($this->once())->method('generate')->with('oro_filtered_attachment', ['id' => 1, 'filename' => 'test.doc', 'filter' => $filerName]);
     $this->attachmentManager->getFilteredImageUrl($this->attachment, $filerName);
 }
 public function testGetImageViewWIthIntegerAttachmentParameter()
 {
     $parentEntity = new TestClass();
     $this->attachment->setFilename('test.doc');
     $attachmentId = 1;
     $repo = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $this->doctrine->expects($this->once())->method('getRepository')->will($this->returnValue($repo));
     $repo->expects($this->once())->method('find')->with($attachmentId)->will($this->returnValue($this->attachment));
     $environment = $this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock();
     $template = new TestTemplate(new \Twig_Environment());
     $environment->expects($this->once())->method('loadTemplate')->will($this->returnValue($template));
     $this->manager->expects($this->once())->method('getResizedImageUrl')->with($this->attachment, 16, 16);
     $this->manager->expects($this->once())->method('getFileUrl');
     $this->extension->getImageView($environment, $parentEntity, $attachmentId);
 }
 public function testCopyAttachmentFile()
 {
     $localFilePath = __DIR__ . '/../Fixtures/testFile/test.txt';
     $sourceStream = new InMemoryBuffer($this->filesystem, $this->attachment->getFilename());
     $sourceStream->open(new StreamMode('wb+'));
     $sourceStream->write(file_get_contents($localFilePath));
     $sourceStream->seek(0);
     $sourceStream->close();
     $resultStream = new InMemoryBuffer($this->filesystem, 'test2.txt');
     $this->filesystem->expects($this->at(0))->method('createStream')->with($this->attachment->getFilename())->will($this->returnValue($sourceStream));
     $this->filesystem->expects($this->at(1))->method('createStream')->with($this->anything())->will($this->returnValue($resultStream));
     $newAttachment = $this->attachmentManager->copyAttachmentFile($this->attachment);
     $this->assertEquals($this->attachment->getOriginalFilename(), $newAttachment->getOriginalFilename());
     $this->assertNotEquals($this->attachment->getFilename(), $newAttachment->getFilename());
     $resultStream->open(new StreamMode('rb+'));
     $resultStream->seek(0);
     $this->assertEquals('Test data', $resultStream->read(100));
 }