Add H264 pseudo streaming tools

This commit is contained in:
Romain Neutron
2014-02-27 14:14:07 +01:00
parent 7f2be7d9aa
commit a3b941c3ec
28 changed files with 864 additions and 112 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace Alchemy\Tests\Phrasea\Http\H264PseudoStream;
use Alchemy\Phrasea\Http\H264PseudoStreaming\Apache;
class ApacheTest extends \PhraseanetPHPUnitAbstract
{
/**
* @dataProvider provideMappingsAndFiles
*/
public function testGetUrl(array $mapping, $expectedRegExp, $pathfile)
{
$mode = new Apache($mapping);
if (null === $expectedRegExp) {
$this->assertNull($mode->getUrl($pathfile));
} else {
$this->assertRegExp($expectedRegExp, (string) $mode->getUrl($pathfile));
}
}
public function provideMappingsAndFiles()
{
$dir = sys_get_temp_dir().'/to/subdef';
$file = $dir . '/to/file';
if (!is_dir(dirname($file))) {
mkdir(dirname($file), 0777, true);
}
if (!is_file($file)) {
touch($file);
}
$mapping = array(array(
'directory' => $dir,
'mount-point' => 'mp4-videos',
'passphrase' => '123456',
));
return array(
array(array(), null, '/path/to/file'),
array($mapping, null, '/path/to/file'),
array($mapping, '/^\/mp4-videos\/[a-zA-Z0-9]+\/[0-9a-f]+\/to\/file$/', $file),
);
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Alchemy\Tests\Phrasea\Http\H264PseudoStreaming;
use Alchemy\Phrasea\Http\H264PseudoStreaming\H264Factory;
class H264FactoryTest extends \PhraseanetPHPUnitAbstract
{
public function testFactoryCreation()
{
$factory = H264Factory::create(self::$DI['app']);
$this->assertInstanceOf('Alchemy\Phrasea\Http\H264PseudoStreaming\H264Factory', $factory);
}
public function testFactoryWithH264Enable()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$factory = new H264Factory($logger, true, 'nginx', $this->getNginxMapping());
$this->assertInstanceOf('Alchemy\Phrasea\Http\H264PseudoStreaming\H264Interface', $factory->createMode());
$this->assertTrue($factory->isH264Enabled());
}
public function testFactoryWithH264Disabled()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$factory = new H264Factory($logger, false, 'nginx',$this->getNginxMapping());
$this->assertInstanceOf('Alchemy\Phrasea\Http\H264PseudoStreaming\NullMode', $factory->createMode());
$this->assertFalse($factory->isH264Enabled());
}
/**
* @expectedException \Alchemy\Phrasea\Exception\InvalidArgumentException
*/
public function testFactoryWithWrongTypeThrowsAnExceptionIfRequired()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$factory = new H264Factory($logger, true, 'wrong-type', $this->getNginxMapping());
$factory->createMode(true);
}
public function testFactoryWithWrongTypeDoesNotThrowsAnException()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$logger->expects($this->once())
->method('error')
->with($this->isType('string'));
$factory = new H264Factory($logger, true, 'wrong-type', $this->getNginxMapping());
$this->assertInstanceOf('Alchemy\Phrasea\Http\H264PseudoStreaming\NullMode', $factory->createMode(false));
}
/**
* @dataProvider provideTypes
*/
public function testFactoryType($type, $mapping, $classmode)
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$factory = new H264Factory($logger, true, $type, $mapping);
$this->assertInstanceOf($classmode, $factory->createMode());
}
public function provideTypes()
{
return array(
array('nginx', $this->getNginxMapping(), 'Alchemy\Phrasea\Http\H264PseudoStreaming\Nginx'),
array('apache', $this->getNginxMapping(), 'Alchemy\Phrasea\Http\H264PseudoStreaming\Apache'),
array('apache2', $this->getNginxMapping(), 'Alchemy\Phrasea\Http\H264PseudoStreaming\Apache'),
);
}
private function getNginxMapping()
{
return array(array(
'directory' => __DIR__ . '/../../../../files/',
'mount-point' => '/protected/',
'passphrase' => 'dfdskqhfsfilddsmfmqsdmlfomqs',
));
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Alchemy\Tests\Phrasea\Http\H264PseudoStream;
use Alchemy\Phrasea\Http\H264PseudoStreaming\Nginx;
class NginxTest extends \PhraseanetPHPUnitAbstract
{
/**
* @dataProvider provideMappingsAndFiles
*/
public function testGetUrl(array $mapping, $expectedRegExp, $pathfile)
{
$mode = new Nginx($mapping);
if (null === $expectedRegExp) {
$this->assertNull($mode->getUrl($pathfile));
} else {
$this->assertRegExp($expectedRegExp, (string) $mode->getUrl($pathfile));
}
}
public function provideMappingsAndFiles()
{
$dir = sys_get_temp_dir().'/to/subdef';
$file = $dir . '/to/file';
if (!is_dir(dirname($file))) {
mkdir(dirname($file), 0777, true);
}
if (!is_file($file)) {
touch($file);
}
$mapping = array(array(
'directory' => $dir,
'mount-point' => 'mp4-videos',
'passphrase' => '123456',
));
return array(
array(array(), null, '/path/to/file'),
array($mapping, null, '/path/to/file'),
array($mapping, '/^\/mp4-videos\/to\/file\?hash=[a-zA-Z0-9-_+]+&expires=[0-9]+/', $file),
);
}
}