コード例 #1
0
    public function testBaseProvider()
    {

        $provider = $this->getProvider();
        $provider->setTemplates(array(
            'edit' => 'edit.twig'
        ));

        $this->assertInternalType('array', $provider->getTemplates());
        $this->assertEquals('edit.twig', $provider->getTemplate('edit'));

        $this->assertInstanceOf('\Sonata\MediaBundle\CDN\CDNInterface', $provider->getCdn());

        $provider->addFormat('small', array());

        $this->assertInternalType('array', $provider->getFormat('small'));

        $media = new \Sonata\MediaBundle\Tests\Entity\Media;
        $media->setContext('test');

        $this->assertEquals('admin', $provider->getFormatName($media, 'admin'));
        $this->assertEquals('reference', $provider->getFormatName($media, 'reference'));
        $this->assertEquals('test_small', $provider->getFormatName($media, 'small'));
        $this->assertEquals('test_small', $provider->getFormatName($media, 'test_small'));
    }
コード例 #2
0
 public function testPHPCRGenerator()
 {
     $generator = new PHPCRGenerator();
     $media = new Media();
     $media->setContext('user');
     $media->setId('nodename');
     $this->assertEquals('user', $generator->generatePath($media));
     $media->setId('/media/nodename');
     $this->assertEquals('user/media', $generator->generatePath($media));
     $media->setId('/media/sub/path/nodename');
     $this->assertEquals('user/media/sub/path', $generator->generatePath($media));
 }
コード例 #3
0
 public function testProvider()
 {
     $generator = new DefaultGenerator();
     $media = new Media();
     $media->setContext('user');
     $media->setId(10);
     $this->assertEquals('user/0001/01', $generator->generatePath($media));
     $media->setId(10000);
     $this->assertEquals('user/0001/11', $generator->generatePath($media));
     $media->setId(12341230);
     $this->assertEquals('user/0124/42', $generator->generatePath($media));
     $media->setId(999999999);
     $this->assertEquals('user/10000/100', $generator->generatePath($media));
 }
コード例 #4
0
 public function testEvent()
 {
     $provider = $this->getProvider();
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $file = new \Symfony\Component\HttpFoundation\File\File(realpath(__DIR__ . '/../fixtures/logo.png'));
     $media = new Media();
     $media->setBinaryContent($file);
     $media->setId(1023456);
     // pre persist the media
     $provider->prePersist($media);
     $this->assertEquals('logo.png', $media->getName(), '::getName() return the file name');
     $this->assertNotNull($media->getProviderReference(), '::getProviderReference() is set');
     // post persit the media
     $provider->postPersist($media);
     $provider->postRemove($media);
 }
コード例 #5
0
 public function testHelperProperies()
 {
     $provider = $this->getProvider();
     $provider->addFormat('admin', array('width' => 100));
     $media = new Media();
     $media->setName('Les tests');
     $media->setProviderReference('ASDASDAS.png');
     $media->setId(10);
     $media->setHeight(100);
     $media->setWidth(100);
     $properties = $provider->getHelperProperties($media, 'admin');
     $this->assertInternalType('array', $properties);
     $this->assertEquals(100, $properties['height']);
     $this->assertEquals(100, $properties['width']);
 }
コード例 #6
0
 /**
  * @group test
  */
 public function testTransformFormatNotSupported()
 {
     $provider = $this->getProvider();
     $file = new \Symfony\Component\HttpFoundation\File\File(realpath(__DIR__ . '/../fixtures/video.mp4'));
     $media = new Media();
     $media->setBinaryContent($file);
     $this->assertNull($provider->transform($media));
     $this->assertNull($media->getWidth(), 'Width staid null');
 }
コード例 #7
0
 public function testEvent()
 {
     $provider = $this->getProvider();
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $file = __DIR__ . '/../fixtures/file.txt';
     $media = new Media();
     $provider->preUpdate($media);
     $this->assertNull($media->getProviderReference());
     $media->setBinaryContent($file);
     $provider->transform($media);
     $this->assertInstanceOf('\\DateTime', $media->getUpdatedAt());
     $this->assertNotNull($media->getProviderReference());
     $provider->postUpdate($media);
     $file = new \Symfony\Component\HttpFoundation\File\File(realpath(__DIR__ . '/../fixtures/file.txt'));
     $media = new Media();
     $media->setBinaryContent($file);
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertEquals('file.txt', $media->getName(), '::getName() return the file name');
     $this->assertNotNull($media->getProviderReference(), '::getProviderReference() is set');
     $this->assertFalse($provider->generatePrivateUrl($media, 'big'), '::generatePrivateUrl() return false');
 }
コード例 #8
0
 public function testDownload()
 {
     $provider = $this->getProvider();
     $file = new File(realpath(__DIR__ . '/../fixtures/FileProviderTest/0011/24/file.txt'));
     $media = new Media();
     $media->setBinaryContent($file);
     $media->setProviderReference('file.txt');
     $media->setContext('FileProviderTest');
     $media->setId(1023456);
     $response = $provider->getDownloadResponse($media, 'reference', 'X-Accel-Redirect');
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\BinaryFileResponse', $response);
 }
コード例 #9
0
 public function testSetFileContents()
 {
     $adapter = new \Gaufrette\Adapter\InMemory(array('testDir'));
     $filesystem = new \Gaufrette\Filesystem($adapter);
     $cdn = new \Sonata\MediaBundle\CDN\Server('/uploads/media');
     $generator = new \Sonata\MediaBundle\Generator\DefaultGenerator();
     $provider = new \Sonata\MediaBundle\Provider\FileProvider('file', $filesystem, $cdn, $generator);
     $media = new Media();
     $media->setId(853);
     $media->setProviderReference(853);
     $provider->setFileContents($media, realpath(__DIR__ . '/../fixtures/file.txt'));
     $this->assertEquals('Hello file text!', $provider->getReferenceFile($media)->getContent());
 }
コード例 #10
0
 public function mediaProvider()
 {
     $file = new \Symfony\Component\HttpFoundation\File\File(realpath(__DIR__ . '/../fixtures/file.txt'));
     $content = file_get_contents(realpath(__DIR__ . '/../fixtures/file.txt'));
     $request = new Request(array(), array(), array(), array(), array(), array(), $content);
     $media1 = new Media();
     $media1->setBinaryContent($file);
     $media1->setContentType('foo');
     $media1->setId(1023456);
     $media2 = new Media();
     $media2->setBinaryContent($request);
     $media2->setContentType('text/plain');
     $media2->setId(1023456);
     $media3 = new Media();
     $media3->setBinaryContent($request);
     $media3->setId(1023456);
     return array(array('\\Symfony\\Component\\HttpFoundation\\File\\File', $media1, false), array('\\Symfony\\Component\\HttpFoundation\\File\\File', $media1), array('\\Symfony\\Component\\HttpFoundation\\File\\File', $media2), array(null, $media3));
 }