More test coverage

Run youtube-dl with --restrict-filenames in order to avoid issues when testing against different locales
This commit is contained in:
Pierre Rudloff 2017-05-31 00:48:50 +02:00
parent 419110f764
commit 0a66dce2b8
7 changed files with 190 additions and 29 deletions

View File

@ -38,7 +38,7 @@ class Config
*
* @var array
*/
public $params = ['--no-warnings', '--ignore-errors', '--flat-playlist'];
public $params = ['--no-warnings', '--ignore-errors', '--flat-playlist', '--restrict-filenames'];
/**
* Enable audio conversion.

View File

@ -485,4 +485,20 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase
new Config(['stream'=>true])
);
}
/**
* Test the locale() function.
*
* @return void
*/
public function testLocale()
{
$this->assertTrue(
$this->controller->locale(
$this->request,
$this->response,
['locale'=>'fr_FR']
)->isRedirect()
);
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* LocaleManagerTest class.
*/
namespace Alltube\Test;
use Alltube\Locale;
use Alltube\LocaleManager;
/**
* Unit tests for the Config class.
*/
class LocaleManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* LocaleManager class instance.
*
* @var LocaleManager
*/
private $localeManager;
/**
* Prepare tests.
*/
protected function setUp()
{
$this->localeManager = new LocaleManager();
}
/**
* Test the getSupportedLocales function.
*
* @return void
*/
public function testGetSupportedLocales()
{
foreach ($this->localeManager->getSupportedLocales() as $locale) {
$this->assertInstanceOf(Locale::class, $locale);
}
}
/**
* Test the getLocale function.
*
* @return void
*/
public function testGetLocale()
{
$this->assertNull($this->localeManager->getLocale());
}
/**
* Test the setLocale function.
*
* @return void
*/
public function testSetLocale()
{
$this->localeManager->setLocale(new Locale('foo_BAR'));
$locale = $this->localeManager->getLocale();
$this->assertInstanceOf(Locale::class, $locale);
$this->assertEquals('foo_BAR', (string) $locale);
}
}

View File

@ -17,13 +17,6 @@ use Slim\Http\Response;
*/
class LocaleMiddlewareTest extends \PHPUnit_Framework_TestCase
{
/**
* Original locale.
*
* @var string
*/
private $origlocale;
/**
* LocaleMiddleware instance.
*
@ -36,23 +29,11 @@ class LocaleMiddlewareTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
$this->origlocale = getenv('LANG');
$container = new Container();
$container['locale'] = new LocaleManager();
$this->middleware = new LocaleMiddleware($container);
}
/**
* Restore environment after the tests.
*
* @return void
*/
protected function tearDown()
{
putenv('LANG='.$this->origlocale);
setlocale(LC_ALL, $this->origlocale);
}
/**
* Test the testLocale() function.
*
@ -114,6 +95,11 @@ class LocaleMiddlewareTest extends \PHPUnit_Framework_TestCase
);
}
/**
* Test that the environment is correctly set up.
*
* @return void
*/
public function testEnv()
{
$this->markTestIncomplete('We need to find a way to reliably test LC_ALL and LANG values');

79
tests/LocaleTest.php Normal file
View File

@ -0,0 +1,79 @@
<?php
/**
* LocaleTest class.
*/
namespace Alltube\Test;
use Alltube\Locale;
/**
* Unit tests for the Config class.
*/
class LocaleTest extends \PHPUnit_Framework_TestCase
{
/**
* Locale class instance.
*
* @var Locale
*/
private $locale;
/**
* Prepare tests.
*/
protected function setUp()
{
$this->locale = new Locale('fr_FR');
}
/**
* Test the __toString function.
*
* @return void
*/
public function testGetToString()
{
$this->assertEquals('fr_FR', $this->locale->__toString());
}
/**
* Test the getFullName function.
*
* @return void
*/
public function testGetFullName()
{
$this->assertEquals('français (France)', $this->locale->getFullName());
}
/**
* Test the getIso15897 function.
*
* @return void
*/
public function testGetIso15897()
{
$this->assertEquals('fr_FR', $this->locale->getIso15897());
}
/**
* Test the getBcp47 function.
*
* @return void
*/
public function testGetBcp47()
{
$this->assertEquals('fr-FR', $this->locale->getBcp47());
}
/**
* Test the getIso3166 function.
*
* @return void
*/
public function testGetIso3166()
{
$this->assertEquals('fr', $this->locale->getIso3166());
}
}

View File

@ -151,32 +151,32 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
return [
[
'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'best[protocol^=http]',
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU",
"It_s_Not_Me_It_s_You_-_Hearts_Under_Fire-M7IpKCZ47pU",
'mp4',
'googlevideo.com',
],
[
'https://www.youtube.com/watch?v=RJJ6FCAXvKg', 22,
"'Heart Attack' - Demi Lovato ".
'(Sam Tsui & Against The Current)-RJJ6FCAXvKg',
"Heart_Attack_-_Demi_Lovato_".
'Sam_Tsui_Against_The_Current-RJJ6FCAXvKg',
'mp4',
'googlevideo.com',
],
[
'https://vimeo.com/24195442', 'best[protocol^=http]',
'Carving the Mountains-24195442',
'Carving_the_Mountains-24195442',
'mp4',
'vimeocdn.com',
],
[
'http://www.bbc.co.uk/programmes/b039g8p7', 'bestaudio/best',
'Leonard Cohen, Kaleidoscope - BBC Radio 4-b039d07m',
'Leonard_Cohen_Kaleidoscope_-_BBC_Radio_4-b039d07m',
'flv',
'bbcodspdns.fcod.llnwd.net',
],
[
'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0', 'bestaudio/best',
'GRIP sucht den Sommerkönig-folge-203-0',
'GRIP_sucht_den_Sommerkonig-folge-203-0',
'f4v',
'edgefcs.net',
],
@ -193,7 +193,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
return [
[
'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'bestvideo+bestaudio',
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU",
"It_s_Not_Me_It_s_You_-_Hearts_Under_Fire-M7IpKCZ47pU",
'mp4',
'googlevideo.com',
],
@ -210,7 +210,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
return [
[
'https://twitter.com/verge/status/813055465324056576/video/1', 'best',
'The Verge - This tiny origami robot can self-fold and complete tasks-813055465324056576',
'The_Verge_-_This_tiny_origami_robot_can_self-fold_and_complete_tasks-813055465324056576',
'mp4',
'video.twimg.com',
],
@ -227,7 +227,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
return [
[
'http://www.canalc2.tv/video/12163', 'rtmp',
'Terrasses du Numérique-12163',
'Terrasses_du_Numerique-12163',
'flv',
'vod-flash.u-strasbg.fr',
],

View File

@ -7,6 +7,8 @@ namespace Alltube\Test;
use Alltube\ViewFactory;
use Slim\Container;
use Slim\Http\Environment;
use Slim\Http\Request;
use Slim\Views\Smarty;
/**
@ -24,4 +26,17 @@ class ViewFactoryTest extends \PHPUnit_Framework_TestCase
$view = ViewFactory::create(new Container());
$this->assertInstanceOf(Smarty::class, $view);
}
/**
* Test the create() function with a X-Forwarded-Proto header.
*
* @return void
*/
public function testCreateWithXForwardedProto()
{
$request = Request::createFromEnvironment(Environment::mock());
$view = ViewFactory::create(new Container(), $request->withHeader('X-Forwarded-Proto', 'https'));
$this->assertInstanceOf(Smarty::class, $view);
}
}