public function testEvent()
 {
     $provider = $this->getProvider();
     $provider->addFormat('big', array('width' => 200, 'height' => null, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent('x9wjql');
     $media->setId(1023456);
     stream_wrapper_unregister('http');
     stream_wrapper_register('http', 'Sonata\\MediaBundle\\Tests\\Provider\\FakeHttpWrapper');
     // pre persist the media
     $provider->prePersist($media);
     $this->assertEquals('Thomas Rabaix - les tests fonctionnels - Symfony Live 2009', $media->getName(), '::getName() return the file name');
     $this->assertEquals('x9wjql', $media->getProviderReference(), '::getProviderReference() is set');
     // post persit the media
     $provider->postPersist($media);
     $provider->postRemove($media);
     $media->setProviderStatus('fake');
     $provider->preUpdate($media);
     $this->assertEquals(MediaInterface::STATUS_OK, $media->getProviderStatus());
     $provider->postUpdate($media);
     $media->setProviderStatus('fake');
     $media->setBinaryContent(null);
     $provider->prePersist($media);
     $this->assertEquals('fake', $media->getProviderStatus());
     $provider->preUpdate($media);
     $this->assertEquals('fake', $media->getProviderStatus());
     $provider->postPersist($media);
     $this->assertEquals('fake', $media->getProviderStatus());
     $provider->preRemove($media);
     stream_wrapper_restore('http');
 }
 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);
 }
 public function testTransformWithUrl()
 {
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_dailymotion.txt'));
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => null, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent('http://www.dailymotion.com/video/x9wjql_asdasdasdsa_asdsds');
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertEquals('Thomas Rabaix - les tests fonctionnels - Symfony Live 2009', $media->getName(), '::getName() return the file name');
     $this->assertEquals('x9wjql', $media->getProviderReference(), '::getProviderReference() is set');
 }
 /**
  * @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');
 }
 /**
  * @dataProvider getUrls
  */
 public function testTransformWithUrl($url)
 {
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_youtube.txt'));
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent($url);
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertSame('Nono le petit robot', $media->getName(), '::getName() return the file name');
     $this->assertSame('BDYAbAtaDzA', $media->getProviderReference(), '::getProviderReference() is set');
 }
 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');
 }
예제 #7
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);
 }
예제 #8
0
 public function getTransformWithUrlMedia()
 {
     $mediaWebsite = new Media();
     $mediaWebsite->setBinaryContent('http://vimeo.com/012341231');
     $mediaWebsite->setId(1023456);
     $mediaPlayer = new Media();
     $mediaPlayer->setBinaryContent('http://player.vimeo.com/video/012341231');
     $mediaPlayer->setId(1023456);
     return array('transform with website url' => array($mediaWebsite), 'transform with player url' => array($mediaPlayer));
 }
 /**
  * @dataProvider getUrls
  */
 public function testTransformWithUrl($url)
 {
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_sapo.txt'));
     $browser->expects($this->at(0))->method('get')->will($this->returnValue($response));
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_sapo_html.txt'));
     $browser->expects($this->at(1))->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent($url);
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertSame('Inferno T5 :: PROMO Ep.106', $media->getName(), '::getName() return the file name');
     $this->assertSame('4MyqjpF3WWNpiTCvNJ60', $media->getProviderReference(), '::getProviderReference() is set');
 }
 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));
 }
 public function testTransformWithUrl()
 {
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_vimeo.txt'));
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent('http://vimeo.com/012341231');
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $provider->prePersist($media);
     $this->assertEquals('Blinky™', $media->getName(), '::getName() return the file name');
     $this->assertEquals('012341231', $media->getProviderReference(), '::getProviderReference() is set');
 }
 /**
  * dataProvider getUrls
  */
 public function testTransformWithUrl($url = null)
 {
     return;
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_playwire.txt'));
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $browser->expects($this->once())->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent($url);
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertSame('Quanto é um trilião elevado a 10?', $media->getName(), '::getName() return the file name');
     $this->assertSame('1000748|4517915', $media->getProviderReference(), '::getProviderReference() is set');
 }
 /**
  * @dataProvider getUrls
  * @group fail
  */
 public function testTransformWithUrl($url)
 {
     $browser = $this->getMockBuilder('Buzz\\Browser')->getMock();
     $response = new Response();
     $response->setContent(file_get_contents(__DIR__ . '/../fixtures/valid_soundcloud.txt'));
     $browser->expects($this->at(0))->method('get')->will($this->returnValue($response));
     $provider = $this->getProvider($browser);
     $provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true));
     $media = new Media();
     $media->setBinaryContent($url);
     $media->setId(1023456);
     // pre persist the media
     $provider->transform($media);
     $this->assertSame('PETDuo\'s Hard Education Podcast by PETDuo', $media->getName(), '::getName() return the file name');
     $this->assertSame('https://soundcloud.com/petduo/sets/petduos-hard-education-podcast', $media->getProviderReference(), '::getProviderReference() is set');
 }