public function load(ObjectManager $manager)
 {
     NodeHelper::createPath($manager->getPhpcrSession(), '/test');
     $testDataDir = realpath(__DIR__ . '/../../app/Resources/data');
     $root = $manager->find(null, '/test');
     // media root
     $mediaRoot = new Generic();
     $mediaRoot->setNodename('media');
     $mediaRoot->setParent($root);
     $manager->persist($mediaRoot);
     // content root
     $contentRoot = new Generic();
     $contentRoot->setNodename('content');
     $contentRoot->setParent($root);
     $manager->persist($contentRoot);
     // File
     $file = new File();
     $file->setParent($mediaRoot);
     $file->setName('file-1.txt');
     $file->setContentFromString('Test file 1.');
     $file->setContentType('text/plain');
     $manager->persist($file);
     // Image
     $image = new Image();
     $image->setParent($mediaRoot);
     $image->setName('cmf-logo.png');
     $image->setFileContentFromFilesystem($testDataDir . '/cmf-logo.png');
     $manager->persist($image);
     $image2 = new Image();
     $image2->setParent($contentRoot);
     $image2->setName('cmf-logo-2.png');
     $image2->setFileContentFromFilesystem($testDataDir . '/cmf-logo.png');
     $manager->persist($image2);
     // Content with image
     $content = new Content();
     $content->setParent($contentRoot);
     $content->setName('content-with-image');
     $content->setTitle('Content document with image embedded');
     $contentImage = new Image();
     $contentImage->setFileContentFromFilesystem($testDataDir . '/cmf-logo.png');
     $content->setFile($contentImage);
     $manager->persist($content);
     // Content with file
     $content2 = new Content();
     $content2->setParent($contentRoot);
     $content2->setName('content-with-file');
     $content2->setTitle('Content document with file attached');
     $contentFile = new File();
     $contentFile->setFileContentFromFilesystem($testDataDir . '/testfile.txt');
     $content2->setFile($contentFile);
     $manager->persist($content2);
     $manager->flush();
 }
 public function testDownloadUrl()
 {
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $router->expects($this->once())->method('generate')->will($this->returnValue('http://www.example.com/media/download/test/media/file-download'));
     $mediaManager = $this->getMock('Symfony\\Cmf\\Bundle\\MediaBundle\\MediaManagerInterface');
     $mediaManager->expects($this->once())->method('getUrlSafePath')->will($this->returnValue('test/media/file-download'));
     $file = new File();
     $file->setName('file-download');
     $file->setId('/test/media/file-download');
     $file->setContentFromString('File download url test.');
     $mediaHelper = new CmfMediaHelper($mediaManager, $router);
     $mediaHelper->downloadUrl($file);
 }
Example #3
0
 /**
  * Create new file and write into it from file pointer.
  * Return new file path or false on error.
  *
  * @param  resource    $fp   file pointer
  * @param  string      $dir  target dir path
  * @param  string      $name file name
  * @param  array       $stat file stat (required by some virtual fs)
  * @return bool|string
  * @author Dmitry (dio) Levashov
  **/
 protected function _save($fp, $dir, $name, $stat)
 {
     $filename = $this->_joinPath($dir, $name);
     $mime = $stat['mime'];
     // @TODO implement a proper system to map a mime-type to a phpcr class
     if (isset($stat['height']) && $stat['height'] && isset($stat['width']) && $stat['width']) {
         $file = new Image();
     } else {
         $file = new File();
     }
     // do not pass file pointer directly to prevent it is closed multiple
     // times causing an error
     $stream = fopen('php://memory', 'rwb+');
     stream_copy_to_stream($fp, $stream);
     $file->setContentFromStream($stream);
     $file->setContentType($mime);
     $file->setId($filename);
     $this->mediaManager->setDefaults($file, $dir);
     $this->dm->persist($file);
     $this->dm->flush();
     return $file->getId();
 }
Example #4
0
 /**
  * @dataProvider getSizeProvider
  */
 public function testSize($content, $expectedSize)
 {
     $file = new File();
     $file->setContentFromString($content);
     $this->assertSame($expectedSize, $file->getSize());
 }