123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341 |
- <?php
- /*
- * This file is part of the webmozart/path-util package.
- *
- * (c) Bernhard Schussek <bschussek@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Webmozart\PathUtil\Tests;
- use Webmozart\PathUtil\Path;
- /**
- * @since 1.0
- *
- * @author Bernhard Schussek <bschussek@gmail.com>
- * @author Thomas Schulz <mail@king2500.net>
- */
- class PathTest extends \PHPUnit_Framework_TestCase
- {
- protected $storedEnv = array();
- public function setUp()
- {
- $this->storedEnv['HOME'] = getenv('HOME');
- $this->storedEnv['HOMEDRIVE'] = getenv('HOMEDRIVE');
- $this->storedEnv['HOMEPATH'] = getenv('HOMEPATH');
- putenv('HOME=/home/webmozart');
- putenv('HOMEDRIVE=');
- putenv('HOMEPATH=');
- }
- public function tearDown()
- {
- putenv('HOME='.$this->storedEnv['HOME']);
- putenv('HOMEDRIVE='.$this->storedEnv['HOMEDRIVE']);
- putenv('HOMEPATH='.$this->storedEnv['HOMEPATH']);
- }
- public function provideCanonicalizationTests()
- {
- return array(
- // relative paths (forward slash)
- array('css/./style.css', 'css/style.css'),
- array('css/../style.css', 'style.css'),
- array('css/./../style.css', 'style.css'),
- array('css/.././style.css', 'style.css'),
- array('css/../../style.css', '../style.css'),
- array('./css/style.css', 'css/style.css'),
- array('../css/style.css', '../css/style.css'),
- array('./../css/style.css', '../css/style.css'),
- array('.././css/style.css', '../css/style.css'),
- array('../../css/style.css', '../../css/style.css'),
- array('', ''),
- array('.', ''),
- array('..', '..'),
- array('./..', '..'),
- array('../.', '..'),
- array('../..', '../..'),
- // relative paths (backslash)
- array('css\\.\\style.css', 'css/style.css'),
- array('css\\..\\style.css', 'style.css'),
- array('css\\.\\..\\style.css', 'style.css'),
- array('css\\..\\.\\style.css', 'style.css'),
- array('css\\..\\..\\style.css', '../style.css'),
- array('.\\css\\style.css', 'css/style.css'),
- array('..\\css\\style.css', '../css/style.css'),
- array('.\\..\\css\\style.css', '../css/style.css'),
- array('..\\.\\css\\style.css', '../css/style.css'),
- array('..\\..\\css\\style.css', '../../css/style.css'),
- // absolute paths (forward slash, UNIX)
- array('/css/style.css', '/css/style.css'),
- array('/css/./style.css', '/css/style.css'),
- array('/css/../style.css', '/style.css'),
- array('/css/./../style.css', '/style.css'),
- array('/css/.././style.css', '/style.css'),
- array('/./css/style.css', '/css/style.css'),
- array('/../css/style.css', '/css/style.css'),
- array('/./../css/style.css', '/css/style.css'),
- array('/.././css/style.css', '/css/style.css'),
- array('/../../css/style.css', '/css/style.css'),
- // absolute paths (backslash, UNIX)
- array('\\css\\style.css', '/css/style.css'),
- array('\\css\\.\\style.css', '/css/style.css'),
- array('\\css\\..\\style.css', '/style.css'),
- array('\\css\\.\\..\\style.css', '/style.css'),
- array('\\css\\..\\.\\style.css', '/style.css'),
- array('\\.\\css\\style.css', '/css/style.css'),
- array('\\..\\css\\style.css', '/css/style.css'),
- array('\\.\\..\\css\\style.css', '/css/style.css'),
- array('\\..\\.\\css\\style.css', '/css/style.css'),
- array('\\..\\..\\css\\style.css', '/css/style.css'),
- // absolute paths (forward slash, Windows)
- array('C:/css/style.css', 'C:/css/style.css'),
- array('C:/css/./style.css', 'C:/css/style.css'),
- array('C:/css/../style.css', 'C:/style.css'),
- array('C:/css/./../style.css', 'C:/style.css'),
- array('C:/css/.././style.css', 'C:/style.css'),
- array('C:/./css/style.css', 'C:/css/style.css'),
- array('C:/../css/style.css', 'C:/css/style.css'),
- array('C:/./../css/style.css', 'C:/css/style.css'),
- array('C:/.././css/style.css', 'C:/css/style.css'),
- array('C:/../../css/style.css', 'C:/css/style.css'),
- // absolute paths (backslash, Windows)
- array('C:\\css\\style.css', 'C:/css/style.css'),
- array('C:\\css\\.\\style.css', 'C:/css/style.css'),
- array('C:\\css\\..\\style.css', 'C:/style.css'),
- array('C:\\css\\.\\..\\style.css', 'C:/style.css'),
- array('C:\\css\\..\\.\\style.css', 'C:/style.css'),
- array('C:\\.\\css\\style.css', 'C:/css/style.css'),
- array('C:\\..\\css\\style.css', 'C:/css/style.css'),
- array('C:\\.\\..\\css\\style.css', 'C:/css/style.css'),
- array('C:\\..\\.\\css\\style.css', 'C:/css/style.css'),
- array('C:\\..\\..\\css\\style.css', 'C:/css/style.css'),
- // Windows special case
- array('C:', 'C:/'),
- // Don't change malformed path
- array('C:css/style.css', 'C:css/style.css'),
- // absolute paths (stream, UNIX)
- array('phar:///css/style.css', 'phar:///css/style.css'),
- array('phar:///css/./style.css', 'phar:///css/style.css'),
- array('phar:///css/../style.css', 'phar:///style.css'),
- array('phar:///css/./../style.css', 'phar:///style.css'),
- array('phar:///css/.././style.css', 'phar:///style.css'),
- array('phar:///./css/style.css', 'phar:///css/style.css'),
- array('phar:///../css/style.css', 'phar:///css/style.css'),
- array('phar:///./../css/style.css', 'phar:///css/style.css'),
- array('phar:///.././css/style.css', 'phar:///css/style.css'),
- array('phar:///../../css/style.css', 'phar:///css/style.css'),
- // absolute paths (stream, Windows)
- array('phar://C:/css/style.css', 'phar://C:/css/style.css'),
- array('phar://C:/css/./style.css', 'phar://C:/css/style.css'),
- array('phar://C:/css/../style.css', 'phar://C:/style.css'),
- array('phar://C:/css/./../style.css', 'phar://C:/style.css'),
- array('phar://C:/css/.././style.css', 'phar://C:/style.css'),
- array('phar://C:/./css/style.css', 'phar://C:/css/style.css'),
- array('phar://C:/../css/style.css', 'phar://C:/css/style.css'),
- array('phar://C:/./../css/style.css', 'phar://C:/css/style.css'),
- array('phar://C:/.././css/style.css', 'phar://C:/css/style.css'),
- array('phar://C:/../../css/style.css', 'phar://C:/css/style.css'),
- // paths with "~" UNIX
- array('~/css/style.css', '/home/webmozart/css/style.css'),
- array('~/css/./style.css', '/home/webmozart/css/style.css'),
- array('~/css/../style.css', '/home/webmozart/style.css'),
- array('~/css/./../style.css', '/home/webmozart/style.css'),
- array('~/css/.././style.css', '/home/webmozart/style.css'),
- array('~/./css/style.css', '/home/webmozart/css/style.css'),
- array('~/../css/style.css', '/home/css/style.css'),
- array('~/./../css/style.css', '/home/css/style.css'),
- array('~/.././css/style.css', '/home/css/style.css'),
- array('~/../../css/style.css', '/css/style.css'),
- );
- }
- /**
- * @dataProvider provideCanonicalizationTests
- */
- public function testCanonicalize($path, $canonicalized)
- {
- $this->assertSame($canonicalized, Path::canonicalize($path));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testCanonicalizeFailsIfInvalidPath()
- {
- Path::canonicalize(array());
- }
- public function provideGetDirectoryTests()
- {
- return array(
- array('/webmozart/puli/style.css', '/webmozart/puli'),
- array('/webmozart/puli', '/webmozart'),
- array('/webmozart', '/'),
- array('/', '/'),
- array('', ''),
- array('\\webmozart\\puli\\style.css', '/webmozart/puli'),
- array('\\webmozart\\puli', '/webmozart'),
- array('\\webmozart', '/'),
- array('\\', '/'),
- array('C:/webmozart/puli/style.css', 'C:/webmozart/puli'),
- array('C:/webmozart/puli', 'C:/webmozart'),
- array('C:/webmozart', 'C:/'),
- array('C:/', 'C:/'),
- array('C:', 'C:/'),
- array('C:\\webmozart\\puli\\style.css', 'C:/webmozart/puli'),
- array('C:\\webmozart\\puli', 'C:/webmozart'),
- array('C:\\webmozart', 'C:/'),
- array('C:\\', 'C:/'),
- array('phar:///webmozart/puli/style.css', 'phar:///webmozart/puli'),
- array('phar:///webmozart/puli', 'phar:///webmozart'),
- array('phar:///webmozart', 'phar:///'),
- array('phar:///', 'phar:///'),
- array('phar://C:/webmozart/puli/style.css', 'phar://C:/webmozart/puli'),
- array('phar://C:/webmozart/puli', 'phar://C:/webmozart'),
- array('phar://C:/webmozart', 'phar://C:/'),
- array('phar://C:/', 'phar://C:/'),
- array('webmozart/puli/style.css', 'webmozart/puli'),
- array('webmozart/puli', 'webmozart'),
- array('webmozart', ''),
- array('webmozart\\puli\\style.css', 'webmozart/puli'),
- array('webmozart\\puli', 'webmozart'),
- array('webmozart', ''),
- array('/webmozart/./puli/style.css', '/webmozart/puli'),
- array('/webmozart/../puli/style.css', '/puli'),
- array('/webmozart/./../puli/style.css', '/puli'),
- array('/webmozart/.././puli/style.css', '/puli'),
- array('/webmozart/../../puli/style.css', '/puli'),
- array('/.', '/'),
- array('/..', '/'),
- array('C:webmozart', ''),
- );
- }
- /**
- * @dataProvider provideGetDirectoryTests
- */
- public function testGetDirectory($path, $directory)
- {
- $this->assertSame($directory, Path::getDirectory($path));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testGetDirectoryFailsIfInvalidPath()
- {
- Path::getDirectory(array());
- }
- public function provideGetFilenameTests()
- {
- return array(
- array('/webmozart/puli/style.css', 'style.css'),
- array('/webmozart/puli/STYLE.CSS', 'STYLE.CSS'),
- array('/webmozart/puli/style.css/', 'style.css'),
- array('/webmozart/puli/', 'puli'),
- array('/webmozart/puli', 'puli'),
- array('/', ''),
- array('', ''),
- );
- }
- /**
- * @dataProvider provideGetFilenameTests
- */
- public function testGetFilename($path, $filename)
- {
- $this->assertSame($filename, Path::getFilename($path));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testGetFilenameFailsIfInvalidPath()
- {
- Path::getFilename(array());
- }
- public function provideGetFilenameWithoutExtensionTests()
- {
- return array(
- array('/webmozart/puli/style.css.twig', null, 'style.css'),
- array('/webmozart/puli/style.css.', null, 'style.css'),
- array('/webmozart/puli/style.css', null, 'style'),
- array('/webmozart/puli/.style.css', null, '.style'),
- array('/webmozart/puli/', null, 'puli'),
- array('/webmozart/puli', null, 'puli'),
- array('/', null, ''),
- array('', null, ''),
- array('/webmozart/puli/style.css', 'css', 'style'),
- array('/webmozart/puli/style.css', '.css', 'style'),
- array('/webmozart/puli/style.css', 'twig', 'style.css'),
- array('/webmozart/puli/style.css', '.twig', 'style.css'),
- array('/webmozart/puli/style.css', '', 'style.css'),
- array('/webmozart/puli/style.css.', '', 'style.css'),
- array('/webmozart/puli/style.css.', '.', 'style.css'),
- array('/webmozart/puli/style.css.', '.css', 'style.css'),
- array('/webmozart/puli/.style.css', 'css', '.style'),
- array('/webmozart/puli/.style.css', '.css', '.style'),
- );
- }
- /**
- * @dataProvider provideGetFilenameWithoutExtensionTests
- */
- public function testGetFilenameWithoutExtension($path, $extension, $filename)
- {
- $this->assertSame($filename, Path::getFilenameWithoutExtension($path, $extension));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testGetFilenameWithoutExtensionFailsIfInvalidPath()
- {
- Path::getFilenameWithoutExtension(array(), '.css');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The extension must be a string or null. Got: array
- */
- public function testGetFilenameWithoutExtensionFailsIfInvalidExtension()
- {
- Path::getFilenameWithoutExtension('/style.css', array());
- }
- public function provideGetExtensionTests()
- {
- $tests = array(
- array('/webmozart/puli/style.css.twig', false, 'twig'),
- array('/webmozart/puli/style.css', false, 'css'),
- array('/webmozart/puli/style.css.', false, ''),
- array('/webmozart/puli/', false, ''),
- array('/webmozart/puli', false, ''),
- array('/', false, ''),
- array('', false, ''),
- array('/webmozart/puli/style.CSS', false, 'CSS'),
- array('/webmozart/puli/style.CSS', true, 'css'),
- array('/webmozart/puli/style.ÄÖÜ', false, 'ÄÖÜ'),
- );
- if (extension_loaded('mbstring')) {
- // This can only be tested, when mbstring is installed
- $tests[] = array('/webmozart/puli/style.ÄÖÜ', true, 'äöü');
- }
- return $tests;
- }
- /**
- * @dataProvider provideGetExtensionTests
- */
- public function testGetExtension($path, $forceLowerCase, $extension)
- {
- $this->assertSame($extension, Path::getExtension($path, $forceLowerCase));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testGetExtensionFailsIfInvalidPath()
- {
- Path::getExtension(array());
- }
- public function provideHasExtensionTests()
- {
- $tests = array(
- array(true, '/webmozart/puli/style.css.twig', null, false),
- array(true, '/webmozart/puli/style.css', null, false),
- array(false, '/webmozart/puli/style.css.', null, false),
- array(false, '/webmozart/puli/', null, false),
- array(false, '/webmozart/puli', null, false),
- array(false, '/', null, false),
- array(false, '', null, false),
- array(true, '/webmozart/puli/style.css.twig', 'twig', false),
- array(false, '/webmozart/puli/style.css.twig', 'css', false),
- array(true, '/webmozart/puli/style.css', 'css', false),
- array(true, '/webmozart/puli/style.css', '.css', false),
- array(true, '/webmozart/puli/style.css.', '', false),
- array(false, '/webmozart/puli/', 'ext', false),
- array(false, '/webmozart/puli', 'ext', false),
- array(false, '/', 'ext', false),
- array(false, '', 'ext', false),
- array(false, '/webmozart/puli/style.css', 'CSS', false),
- array(true, '/webmozart/puli/style.css', 'CSS', true),
- array(false, '/webmozart/puli/style.CSS', 'css', false),
- array(true, '/webmozart/puli/style.CSS', 'css', true),
- array(true, '/webmozart/puli/style.ÄÖÜ', 'ÄÖÜ', false),
- array(true, '/webmozart/puli/style.css', array('ext', 'css'), false),
- array(true, '/webmozart/puli/style.css', array('.ext', '.css'), false),
- array(true, '/webmozart/puli/style.css.', array('ext', ''), false),
- array(false, '/webmozart/puli/style.css', array('foo', 'bar', ''), false),
- array(false, '/webmozart/puli/style.css', array('.foo', '.bar', ''), false),
- );
- if (extension_loaded('mbstring')) {
- // This can only be tested, when mbstring is installed
- $tests[] = array(true, '/webmozart/puli/style.ÄÖÜ', 'äöü', true);
- $tests[] = array(true, '/webmozart/puli/style.ÄÖÜ', array('äöü'), true);
- }
- return $tests;
- }
- /**
- * @dataProvider provideHasExtensionTests
- */
- public function testHasExtension($hasExtension, $path, $extension, $ignoreCase)
- {
- $this->assertSame($hasExtension, Path::hasExtension($path, $extension, $ignoreCase));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testHasExtensionFailsIfInvalidPath()
- {
- Path::hasExtension(array());
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The extensions must be strings. Got: stdClass
- */
- public function testHasExtensionFailsIfInvalidExtension()
- {
- Path::hasExtension('/style.css', (object) array());
- }
- public function provideChangeExtensionTests()
- {
- return array(
- array('/webmozart/puli/style.css.twig', 'html', '/webmozart/puli/style.css.html'),
- array('/webmozart/puli/style.css', 'sass', '/webmozart/puli/style.sass'),
- array('/webmozart/puli/style.css', '.sass', '/webmozart/puli/style.sass'),
- array('/webmozart/puli/style.css', '', '/webmozart/puli/style.'),
- array('/webmozart/puli/style.css.', 'twig', '/webmozart/puli/style.css.twig'),
- array('/webmozart/puli/style.css.', '', '/webmozart/puli/style.css.'),
- array('/webmozart/puli/style.css', 'äöü', '/webmozart/puli/style.äöü'),
- array('/webmozart/puli/style.äöü', 'css', '/webmozart/puli/style.css'),
- array('/webmozart/puli/', 'css', '/webmozart/puli/'),
- array('/webmozart/puli', 'css', '/webmozart/puli.css'),
- array('/', 'css', '/'),
- array('', 'css', ''),
- );
- }
- /**
- * @dataProvider provideChangeExtensionTests
- */
- public function testChangeExtension($path, $extension, $pathExpected)
- {
- static $call = 0;
- $this->assertSame($pathExpected, Path::changeExtension($path, $extension));
- ++$call;
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testChangeExtensionFailsIfInvalidPath()
- {
- Path::changeExtension(array(), '.sass');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The extension must be a string. Got: array
- */
- public function testChangeExtensionFailsIfInvalidExtension()
- {
- Path::changeExtension('/style.css', array());
- }
- public function provideIsAbsolutePathTests()
- {
- return array(
- array('/css/style.css', true),
- array('/', true),
- array('css/style.css', false),
- array('', false),
- array('\\css\\style.css', true),
- array('\\', true),
- array('css\\style.css', false),
- array('C:/css/style.css', true),
- array('D:/', true),
- array('E:\\css\\style.css', true),
- array('F:\\', true),
- array('phar:///css/style.css', true),
- array('phar:///', true),
- // Windows special case
- array('C:', true),
- // Not considered absolute
- array('C:css/style.css', false),
- );
- }
- /**
- * @dataProvider provideIsAbsolutePathTests
- */
- public function testIsAbsolute($path, $isAbsolute)
- {
- $this->assertSame($isAbsolute, Path::isAbsolute($path));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testIsAbsoluteFailsIfInvalidPath()
- {
- Path::isAbsolute(array());
- }
- /**
- * @dataProvider provideIsAbsolutePathTests
- */
- public function testIsRelative($path, $isAbsolute)
- {
- $this->assertSame(!$isAbsolute, Path::isRelative($path));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testIsRelativeFailsIfInvalidPath()
- {
- Path::isRelative(array());
- }
- public function provideGetRootTests()
- {
- return array(
- array('/css/style.css', '/'),
- array('/', '/'),
- array('css/style.css', ''),
- array('', ''),
- array('\\css\\style.css', '/'),
- array('\\', '/'),
- array('css\\style.css', ''),
- array('C:/css/style.css', 'C:/'),
- array('C:/', 'C:/'),
- array('C:', 'C:/'),
- array('D:\\css\\style.css', 'D:/'),
- array('D:\\', 'D:/'),
- array('phar:///css/style.css', 'phar:///'),
- array('phar:///', 'phar:///'),
- array('phar://C:/css/style.css', 'phar://C:/'),
- array('phar://C:/', 'phar://C:/'),
- array('phar://C:', 'phar://C:/'),
- );
- }
- /**
- * @dataProvider provideGetRootTests
- */
- public function testGetRoot($path, $root)
- {
- $this->assertSame($root, Path::getRoot($path));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testGetRootFailsIfInvalidPath()
- {
- Path::getRoot(array());
- }
- public function providePathTests()
- {
- return array(
- // relative to absolute path
- array('css/style.css', '/webmozart/puli', '/webmozart/puli/css/style.css'),
- array('../css/style.css', '/webmozart/puli', '/webmozart/css/style.css'),
- array('../../css/style.css', '/webmozart/puli', '/css/style.css'),
- // relative to root
- array('css/style.css', '/', '/css/style.css'),
- array('css/style.css', 'C:', 'C:/css/style.css'),
- array('css/style.css', 'C:/', 'C:/css/style.css'),
- // same sub directories in different base directories
- array('../../puli/css/style.css', '/webmozart/css', '/puli/css/style.css'),
- array('', '/webmozart/puli', '/webmozart/puli'),
- array('..', '/webmozart/puli', '/webmozart'),
- );
- }
- public function provideMakeAbsoluteTests()
- {
- return array_merge($this->providePathTests(), array(
- // collapse dots
- array('css/./style.css', '/webmozart/puli', '/webmozart/puli/css/style.css'),
- array('css/../style.css', '/webmozart/puli', '/webmozart/puli/style.css'),
- array('css/./../style.css', '/webmozart/puli', '/webmozart/puli/style.css'),
- array('css/.././style.css', '/webmozart/puli', '/webmozart/puli/style.css'),
- array('./css/style.css', '/webmozart/puli', '/webmozart/puli/css/style.css'),
- array('css\\.\\style.css', '\\webmozart\\puli', '/webmozart/puli/css/style.css'),
- array('css\\..\\style.css', '\\webmozart\\puli', '/webmozart/puli/style.css'),
- array('css\\.\\..\\style.css', '\\webmozart\\puli', '/webmozart/puli/style.css'),
- array('css\\..\\.\\style.css', '\\webmozart\\puli', '/webmozart/puli/style.css'),
- array('.\\css\\style.css', '\\webmozart\\puli', '/webmozart/puli/css/style.css'),
- // collapse dots on root
- array('./css/style.css', '/', '/css/style.css'),
- array('../css/style.css', '/', '/css/style.css'),
- array('../css/./style.css', '/', '/css/style.css'),
- array('../css/../style.css', '/', '/style.css'),
- array('../css/./../style.css', '/', '/style.css'),
- array('../css/.././style.css', '/', '/style.css'),
- array('.\\css\\style.css', '\\', '/css/style.css'),
- array('..\\css\\style.css', '\\', '/css/style.css'),
- array('..\\css\\.\\style.css', '\\', '/css/style.css'),
- array('..\\css\\..\\style.css', '\\', '/style.css'),
- array('..\\css\\.\\..\\style.css', '\\', '/style.css'),
- array('..\\css\\..\\.\\style.css', '\\', '/style.css'),
- array('./css/style.css', 'C:/', 'C:/css/style.css'),
- array('../css/style.css', 'C:/', 'C:/css/style.css'),
- array('../css/./style.css', 'C:/', 'C:/css/style.css'),
- array('../css/../style.css', 'C:/', 'C:/style.css'),
- array('../css/./../style.css', 'C:/', 'C:/style.css'),
- array('../css/.././style.css', 'C:/', 'C:/style.css'),
- array('.\\css\\style.css', 'C:\\', 'C:/css/style.css'),
- array('..\\css\\style.css', 'C:\\', 'C:/css/style.css'),
- array('..\\css\\.\\style.css', 'C:\\', 'C:/css/style.css'),
- array('..\\css\\..\\style.css', 'C:\\', 'C:/style.css'),
- array('..\\css\\.\\..\\style.css', 'C:\\', 'C:/style.css'),
- array('..\\css\\..\\.\\style.css', 'C:\\', 'C:/style.css'),
- array('./css/style.css', 'phar:///', 'phar:///css/style.css'),
- array('../css/style.css', 'phar:///', 'phar:///css/style.css'),
- array('../css/./style.css', 'phar:///', 'phar:///css/style.css'),
- array('../css/../style.css', 'phar:///', 'phar:///style.css'),
- array('../css/./../style.css', 'phar:///', 'phar:///style.css'),
- array('../css/.././style.css', 'phar:///', 'phar:///style.css'),
- array('./css/style.css', 'phar://C:/', 'phar://C:/css/style.css'),
- array('../css/style.css', 'phar://C:/', 'phar://C:/css/style.css'),
- array('../css/./style.css', 'phar://C:/', 'phar://C:/css/style.css'),
- array('../css/../style.css', 'phar://C:/', 'phar://C:/style.css'),
- array('../css/./../style.css', 'phar://C:/', 'phar://C:/style.css'),
- array('../css/.././style.css', 'phar://C:/', 'phar://C:/style.css'),
- // absolute paths
- array('/css/style.css', '/webmozart/puli', '/css/style.css'),
- array('\\css\\style.css', '/webmozart/puli', '/css/style.css'),
- array('C:/css/style.css', 'C:/webmozart/puli', 'C:/css/style.css'),
- array('D:\\css\\style.css', 'D:/webmozart/puli', 'D:/css/style.css'),
- ));
- }
- /**
- * @dataProvider provideMakeAbsoluteTests
- */
- public function testMakeAbsolute($relativePath, $basePath, $absolutePath)
- {
- $this->assertSame($absolutePath, Path::makeAbsolute($relativePath, $basePath));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testMakeAbsoluteFailsIfInvalidPath()
- {
- Path::makeAbsolute(array(), '/webmozart/puli');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The base path must be a non-empty string. Got: array
- */
- public function testMakeAbsoluteFailsIfInvalidBasePath()
- {
- Path::makeAbsolute('css/style.css', array());
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The base path "webmozart/puli" is not an absolute path.
- */
- public function testMakeAbsoluteFailsIfBasePathNotAbsolute()
- {
- Path::makeAbsolute('css/style.css', 'webmozart/puli');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The base path must be a non-empty string. Got: ""
- */
- public function testMakeAbsoluteFailsIfBasePathEmpty()
- {
- Path::makeAbsolute('css/style.css', '');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The base path must be a non-empty string. Got: NULL
- */
- public function testMakeAbsoluteFailsIfBasePathNull()
- {
- Path::makeAbsolute('css/style.css', null);
- }
- public function provideAbsolutePathsWithDifferentRoots()
- {
- return array(
- array('C:/css/style.css', '/webmozart/puli'),
- array('C:/css/style.css', '\\webmozart\\puli'),
- array('C:\\css\\style.css', '/webmozart/puli'),
- array('C:\\css\\style.css', '\\webmozart\\puli'),
- array('/css/style.css', 'C:/webmozart/puli'),
- array('/css/style.css', 'C:\\webmozart\\puli'),
- array('\\css\\style.css', 'C:/webmozart/puli'),
- array('\\css\\style.css', 'C:\\webmozart\\puli'),
- array('D:/css/style.css', 'C:/webmozart/puli'),
- array('D:/css/style.css', 'C:\\webmozart\\puli'),
- array('D:\\css\\style.css', 'C:/webmozart/puli'),
- array('D:\\css\\style.css', 'C:\\webmozart\\puli'),
- array('phar:///css/style.css', '/webmozart/puli'),
- array('/css/style.css', 'phar:///webmozart/puli'),
- array('phar://C:/css/style.css', 'C:/webmozart/puli'),
- array('phar://C:/css/style.css', 'C:\\webmozart\\puli'),
- array('phar://C:\\css\\style.css', 'C:/webmozart/puli'),
- array('phar://C:\\css\\style.css', 'C:\\webmozart\\puli'),
- );
- }
- /**
- * @dataProvider provideAbsolutePathsWithDifferentRoots
- */
- public function testMakeAbsoluteDoesNotFailIfDifferentRoot($basePath, $absolutePath)
- {
- // If a path in partition D: is passed, but $basePath is in partition
- // C:, the path should be returned unchanged
- $this->assertSame(Path::canonicalize($absolutePath), Path::makeAbsolute($absolutePath, $basePath));
- }
- public function provideMakeRelativeTests()
- {
- $paths = array_map(function (array $arguments) {
- return array($arguments[2], $arguments[1], $arguments[0]);
- }, $this->providePathTests());
- return array_merge($paths, array(
- array('/webmozart/puli/./css/style.css', '/webmozart/puli', 'css/style.css'),
- array('/webmozart/puli/../css/style.css', '/webmozart/puli', '../css/style.css'),
- array('/webmozart/puli/.././css/style.css', '/webmozart/puli', '../css/style.css'),
- array('/webmozart/puli/./../css/style.css', '/webmozart/puli', '../css/style.css'),
- array('/webmozart/puli/../../css/style.css', '/webmozart/puli', '../../css/style.css'),
- array('/webmozart/puli/css/style.css', '/webmozart/./puli', 'css/style.css'),
- array('/webmozart/puli/css/style.css', '/webmozart/../puli', '../webmozart/puli/css/style.css'),
- array('/webmozart/puli/css/style.css', '/webmozart/./../puli', '../webmozart/puli/css/style.css'),
- array('/webmozart/puli/css/style.css', '/webmozart/.././puli', '../webmozart/puli/css/style.css'),
- array('/webmozart/puli/css/style.css', '/webmozart/../../puli', '../webmozart/puli/css/style.css'),
- // first argument shorter than second
- array('/css', '/webmozart/puli', '../../css'),
- // second argument shorter than first
- array('/webmozart/puli', '/css', '../webmozart/puli'),
- array('\\webmozart\\puli\\css\\style.css', '\\webmozart\\puli', 'css/style.css'),
- array('\\webmozart\\css\\style.css', '\\webmozart\\puli', '../css/style.css'),
- array('\\css\\style.css', '\\webmozart\\puli', '../../css/style.css'),
- array('C:/webmozart/puli/css/style.css', 'C:/webmozart/puli', 'css/style.css'),
- array('C:/webmozart/css/style.css', 'C:/webmozart/puli', '../css/style.css'),
- array('C:/css/style.css', 'C:/webmozart/puli', '../../css/style.css'),
- array('C:\\webmozart\\puli\\css\\style.css', 'C:\\webmozart\\puli', 'css/style.css'),
- array('C:\\webmozart\\css\\style.css', 'C:\\webmozart\\puli', '../css/style.css'),
- array('C:\\css\\style.css', 'C:\\webmozart\\puli', '../../css/style.css'),
- array('phar:///webmozart/puli/css/style.css', 'phar:///webmozart/puli', 'css/style.css'),
- array('phar:///webmozart/css/style.css', 'phar:///webmozart/puli', '../css/style.css'),
- array('phar:///css/style.css', 'phar:///webmozart/puli', '../../css/style.css'),
- array('phar://C:/webmozart/puli/css/style.css', 'phar://C:/webmozart/puli', 'css/style.css'),
- array('phar://C:/webmozart/css/style.css', 'phar://C:/webmozart/puli', '../css/style.css'),
- array('phar://C:/css/style.css', 'phar://C:/webmozart/puli', '../../css/style.css'),
- // already relative + already in root basepath
- array('../style.css', '/', 'style.css'),
- array('./style.css', '/', 'style.css'),
- array('../../style.css', '/', 'style.css'),
- array('..\\style.css', 'C:\\', 'style.css'),
- array('.\\style.css', 'C:\\', 'style.css'),
- array('..\\..\\style.css', 'C:\\', 'style.css'),
- array('../style.css', 'C:/', 'style.css'),
- array('./style.css', 'C:/', 'style.css'),
- array('../../style.css', 'C:/', 'style.css'),
- array('..\\style.css', '\\', 'style.css'),
- array('.\\style.css', '\\', 'style.css'),
- array('..\\..\\style.css', '\\', 'style.css'),
- array('../style.css', 'phar:///', 'style.css'),
- array('./style.css', 'phar:///', 'style.css'),
- array('../../style.css', 'phar:///', 'style.css'),
- array('..\\style.css', 'phar://C:\\', 'style.css'),
- array('.\\style.css', 'phar://C:\\', 'style.css'),
- array('..\\..\\style.css', 'phar://C:\\', 'style.css'),
- array('css/../style.css', '/', 'style.css'),
- array('css/./style.css', '/', 'css/style.css'),
- array('css\\..\\style.css', 'C:\\', 'style.css'),
- array('css\\.\\style.css', 'C:\\', 'css/style.css'),
- array('css/../style.css', 'C:/', 'style.css'),
- array('css/./style.css', 'C:/', 'css/style.css'),
- array('css\\..\\style.css', '\\', 'style.css'),
- array('css\\.\\style.css', '\\', 'css/style.css'),
- array('css/../style.css', 'phar:///', 'style.css'),
- array('css/./style.css', 'phar:///', 'css/style.css'),
- array('css\\..\\style.css', 'phar://C:\\', 'style.css'),
- array('css\\.\\style.css', 'phar://C:\\', 'css/style.css'),
- // already relative
- array('css/style.css', '/webmozart/puli', 'css/style.css'),
- array('css\\style.css', '\\webmozart\\puli', 'css/style.css'),
- // both relative
- array('css/style.css', 'webmozart/puli', '../../css/style.css'),
- array('css\\style.css', 'webmozart\\puli', '../../css/style.css'),
- // relative to empty
- array('css/style.css', '', 'css/style.css'),
- array('css\\style.css', '', 'css/style.css'),
- // different slashes in path and base path
- array('/webmozart/puli/css/style.css', '\\webmozart\\puli', 'css/style.css'),
- array('\\webmozart\\puli\\css\\style.css', '/webmozart/puli', 'css/style.css'),
- ));
- }
- /**
- * @dataProvider provideMakeRelativeTests
- */
- public function testMakeRelative($absolutePath, $basePath, $relativePath)
- {
- $this->assertSame($relativePath, Path::makeRelative($absolutePath, $basePath));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testMakeRelativeFailsIfInvalidPath()
- {
- Path::makeRelative(array(), '/webmozart/puli');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The base path must be a string. Got: array
- */
- public function testMakeRelativeFailsIfInvalidBasePath()
- {
- Path::makeRelative('/webmozart/puli/css/style.css', array());
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The absolute path "/webmozart/puli/css/style.css" cannot be made relative to the relative path "webmozart/puli". You should provide an absolute base path instead.
- */
- public function testMakeRelativeFailsIfAbsolutePathAndBasePathNotAbsolute()
- {
- Path::makeRelative('/webmozart/puli/css/style.css', 'webmozart/puli');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The absolute path "/webmozart/puli/css/style.css" cannot be made relative to the relative path "". You should provide an absolute base path instead.
- */
- public function testMakeRelativeFailsIfAbsolutePathAndBasePathEmpty()
- {
- Path::makeRelative('/webmozart/puli/css/style.css', '');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The base path must be a string. Got: NULL
- */
- public function testMakeRelativeFailsIfBasePathNull()
- {
- Path::makeRelative('/webmozart/puli/css/style.css', null);
- }
- /**
- * @dataProvider provideAbsolutePathsWithDifferentRoots
- * @expectedException \InvalidArgumentException
- */
- public function testMakeRelativeFailsIfDifferentRoot($absolutePath, $basePath)
- {
- Path::makeRelative($absolutePath, $basePath);
- }
- public function provideIsLocalTests()
- {
- return array(
- array('/bg.png', true),
- array('bg.png', true),
- array('http://example.com/bg.png', false),
- array('http://example.com', false),
- array('', false),
- );
- }
- /**
- * @dataProvider provideIsLocalTests
- */
- public function testIsLocal($path, $isLocal)
- {
- $this->assertSame($isLocal, Path::isLocal($path));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testIsLocalFailsIfInvalidPath()
- {
- Path::isLocal(array());
- }
- public function provideGetLongestCommonBasePathTests()
- {
- return array(
- // same paths
- array(array('/base/path', '/base/path'), '/base/path'),
- array(array('C:/base/path', 'C:/base/path'), 'C:/base/path'),
- array(array('C:\\base\\path', 'C:\\base\\path'), 'C:/base/path'),
- array(array('C:/base/path', 'C:\\base\\path'), 'C:/base/path'),
- array(array('phar:///base/path', 'phar:///base/path'), 'phar:///base/path'),
- array(array('phar://C:/base/path', 'phar://C:/base/path'), 'phar://C:/base/path'),
- // trailing slash
- array(array('/base/path/', '/base/path'), '/base/path'),
- array(array('C:/base/path/', 'C:/base/path'), 'C:/base/path'),
- array(array('C:\\base\\path\\', 'C:\\base\\path'), 'C:/base/path'),
- array(array('C:/base/path/', 'C:\\base\\path'), 'C:/base/path'),
- array(array('phar:///base/path/', 'phar:///base/path'), 'phar:///base/path'),
- array(array('phar://C:/base/path/', 'phar://C:/base/path'), 'phar://C:/base/path'),
- array(array('/base/path', '/base/path/'), '/base/path'),
- array(array('C:/base/path', 'C:/base/path/'), 'C:/base/path'),
- array(array('C:\\base\\path', 'C:\\base\\path\\'), 'C:/base/path'),
- array(array('C:/base/path', 'C:\\base\\path\\'), 'C:/base/path'),
- array(array('phar:///base/path', 'phar:///base/path/'), 'phar:///base/path'),
- array(array('phar://C:/base/path', 'phar://C:/base/path/'), 'phar://C:/base/path'),
- // first in second
- array(array('/base/path/sub', '/base/path'), '/base/path'),
- array(array('C:/base/path/sub', 'C:/base/path'), 'C:/base/path'),
- array(array('C:\\base\\path\\sub', 'C:\\base\\path'), 'C:/base/path'),
- array(array('C:/base/path/sub', 'C:\\base\\path'), 'C:/base/path'),
- array(array('phar:///base/path/sub', 'phar:///base/path'), 'phar:///base/path'),
- array(array('phar://C:/base/path/sub', 'phar://C:/base/path'), 'phar://C:/base/path'),
- // second in first
- array(array('/base/path', '/base/path/sub'), '/base/path'),
- array(array('C:/base/path', 'C:/base/path/sub'), 'C:/base/path'),
- array(array('C:\\base\\path', 'C:\\base\\path\\sub'), 'C:/base/path'),
- array(array('C:/base/path', 'C:\\base\\path\\sub'), 'C:/base/path'),
- array(array('phar:///base/path', 'phar:///base/path/sub'), 'phar:///base/path'),
- array(array('phar://C:/base/path', 'phar://C:/base/path/sub'), 'phar://C:/base/path'),
- // first is prefix
- array(array('/base/path/di', '/base/path/dir'), '/base/path'),
- array(array('C:/base/path/di', 'C:/base/path/dir'), 'C:/base/path'),
- array(array('C:\\base\\path\\di', 'C:\\base\\path\\dir'), 'C:/base/path'),
- array(array('C:/base/path/di', 'C:\\base\\path\\dir'), 'C:/base/path'),
- array(array('phar:///base/path/di', 'phar:///base/path/dir'), 'phar:///base/path'),
- array(array('phar://C:/base/path/di', 'phar://C:/base/path/dir'), 'phar://C:/base/path'),
- // second is prefix
- array(array('/base/path/dir', '/base/path/di'), '/base/path'),
- array(array('C:/base/path/dir', 'C:/base/path/di'), 'C:/base/path'),
- array(array('C:\\base\\path\\dir', 'C:\\base\\path\\di'), 'C:/base/path'),
- array(array('C:/base/path/dir', 'C:\\base\\path\\di'), 'C:/base/path'),
- array(array('phar:///base/path/dir', 'phar:///base/path/di'), 'phar:///base/path'),
- array(array('phar://C:/base/path/dir', 'phar://C:/base/path/di'), 'phar://C:/base/path'),
- // root is common base path
- array(array('/first', '/second'), '/'),
- array(array('C:/first', 'C:/second'), 'C:/'),
- array(array('C:\\first', 'C:\\second'), 'C:/'),
- array(array('C:/first', 'C:\\second'), 'C:/'),
- array(array('phar:///first', 'phar:///second'), 'phar:///'),
- array(array('phar://C:/first', 'phar://C:/second'), 'phar://C:/'),
- // windows vs unix
- array(array('/base/path', 'C:/base/path'), null),
- array(array('C:/base/path', '/base/path'), null),
- array(array('/base/path', 'C:\\base\\path'), null),
- array(array('phar:///base/path', 'phar://C:/base/path'), null),
- // different partitions
- array(array('C:/base/path', 'D:/base/path'), null),
- array(array('C:/base/path', 'D:\\base\\path'), null),
- array(array('C:\\base\\path', 'D:\\base\\path'), null),
- array(array('phar://C:/base/path', 'phar://D:/base/path'), null),
- // three paths
- array(array('/base/path/foo', '/base/path', '/base/path/bar'), '/base/path'),
- array(array('C:/base/path/foo', 'C:/base/path', 'C:/base/path/bar'), 'C:/base/path'),
- array(array('C:\\base\\path\\foo', 'C:\\base\\path', 'C:\\base\\path\\bar'), 'C:/base/path'),
- array(array('C:/base/path//foo', 'C:/base/path', 'C:\\base\\path\\bar'), 'C:/base/path'),
- array(array('phar:///base/path/foo', 'phar:///base/path', 'phar:///base/path/bar'), 'phar:///base/path'),
- array(array('phar://C:/base/path/foo', 'phar://C:/base/path', 'phar://C:/base/path/bar'), 'phar://C:/base/path'),
- // three paths with root
- array(array('/base/path/foo', '/', '/base/path/bar'), '/'),
- array(array('C:/base/path/foo', 'C:/', 'C:/base/path/bar'), 'C:/'),
- array(array('C:\\base\\path\\foo', 'C:\\', 'C:\\base\\path\\bar'), 'C:/'),
- array(array('C:/base/path//foo', 'C:/', 'C:\\base\\path\\bar'), 'C:/'),
- array(array('phar:///base/path/foo', 'phar:///', 'phar:///base/path/bar'), 'phar:///'),
- array(array('phar://C:/base/path/foo', 'phar://C:/', 'phar://C:/base/path/bar'), 'phar://C:/'),
- // three paths, different roots
- array(array('/base/path/foo', 'C:/base/path', '/base/path/bar'), null),
- array(array('/base/path/foo', 'C:\\base\\path', '/base/path/bar'), null),
- array(array('C:/base/path/foo', 'D:/base/path', 'C:/base/path/bar'), null),
- array(array('C:\\base\\path\\foo', 'D:\\base\\path', 'C:\\base\\path\\bar'), null),
- array(array('C:/base/path//foo', 'D:/base/path', 'C:\\base\\path\\bar'), null),
- array(array('phar:///base/path/foo', 'phar://C:/base/path', 'phar:///base/path/bar'), null),
- array(array('phar://C:/base/path/foo', 'phar://D:/base/path', 'phar://C:/base/path/bar'), null),
- // only one path
- array(array('/base/path'), '/base/path'),
- array(array('C:/base/path'), 'C:/base/path'),
- array(array('C:\\base\\path'), 'C:/base/path'),
- array(array('phar:///base/path'), 'phar:///base/path'),
- array(array('phar://C:/base/path'), 'phar://C:/base/path'),
- );
- }
- /**
- * @dataProvider provideGetLongestCommonBasePathTests
- */
- public function testGetLongestCommonBasePath(array $paths, $basePath)
- {
- $this->assertSame($basePath, Path::getLongestCommonBasePath($paths));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The paths must be strings. Got: array
- */
- public function testGetLongestCommonBasePathFailsIfInvalidPath()
- {
- Path::getLongestCommonBasePath(array(array()));
- }
- public function provideIsBasePathTests()
- {
- return array(
- // same paths
- array('/base/path', '/base/path', true),
- array('C:/base/path', 'C:/base/path', true),
- array('C:\\base\\path', 'C:\\base\\path', true),
- array('C:/base/path', 'C:\\base\\path', true),
- array('phar:///base/path', 'phar:///base/path', true),
- array('phar://C:/base/path', 'phar://C:/base/path', true),
- // trailing slash
- array('/base/path/', '/base/path', true),
- array('C:/base/path/', 'C:/base/path', true),
- array('C:\\base\\path\\', 'C:\\base\\path', true),
- array('C:/base/path/', 'C:\\base\\path', true),
- array('phar:///base/path/', 'phar:///base/path', true),
- array('phar://C:/base/path/', 'phar://C:/base/path', true),
- array('/base/path', '/base/path/', true),
- array('C:/base/path', 'C:/base/path/', true),
- array('C:\\base\\path', 'C:\\base\\path\\', true),
- array('C:/base/path', 'C:\\base\\path\\', true),
- array('phar:///base/path', 'phar:///base/path/', true),
- array('phar://C:/base/path', 'phar://C:/base/path/', true),
- // first in second
- array('/base/path/sub', '/base/path', false),
- array('C:/base/path/sub', 'C:/base/path', false),
- array('C:\\base\\path\\sub', 'C:\\base\\path', false),
- array('C:/base/path/sub', 'C:\\base\\path', false),
- array('phar:///base/path/sub', 'phar:///base/path', false),
- array('phar://C:/base/path/sub', 'phar://C:/base/path', false),
- // second in first
- array('/base/path', '/base/path/sub', true),
- array('C:/base/path', 'C:/base/path/sub', true),
- array('C:\\base\\path', 'C:\\base\\path\\sub', true),
- array('C:/base/path', 'C:\\base\\path\\sub', true),
- array('phar:///base/path', 'phar:///base/path/sub', true),
- array('phar://C:/base/path', 'phar://C:/base/path/sub', true),
- // first is prefix
- array('/base/path/di', '/base/path/dir', false),
- array('C:/base/path/di', 'C:/base/path/dir', false),
- array('C:\\base\\path\\di', 'C:\\base\\path\\dir', false),
- array('C:/base/path/di', 'C:\\base\\path\\dir', false),
- array('phar:///base/path/di', 'phar:///base/path/dir', false),
- array('phar://C:/base/path/di', 'phar://C:/base/path/dir', false),
- // second is prefix
- array('/base/path/dir', '/base/path/di', false),
- array('C:/base/path/dir', 'C:/base/path/di', false),
- array('C:\\base\\path\\dir', 'C:\\base\\path\\di', false),
- array('C:/base/path/dir', 'C:\\base\\path\\di', false),
- array('phar:///base/path/dir', 'phar:///base/path/di', false),
- array('phar://C:/base/path/dir', 'phar://C:/base/path/di', false),
- // root
- array('/', '/second', true),
- array('C:/', 'C:/second', true),
- array('C:', 'C:/second', true),
- array('C:\\', 'C:\\second', true),
- array('C:/', 'C:\\second', true),
- array('phar:///', 'phar:///second', true),
- array('phar://C:/', 'phar://C:/second', true),
- // windows vs unix
- array('/base/path', 'C:/base/path', false),
- array('C:/base/path', '/base/path', false),
- array('/base/path', 'C:\\base\\path', false),
- array('/base/path', 'phar:///base/path', false),
- array('phar:///base/path', 'phar://C:/base/path', false),
- // different partitions
- array('C:/base/path', 'D:/base/path', false),
- array('C:/base/path', 'D:\\base\\path', false),
- array('C:\\base\\path', 'D:\\base\\path', false),
- array('C:/base/path', 'phar://C:/base/path', false),
- array('phar://C:/base/path', 'phar://D:/base/path', false),
- );
- }
- /**
- * @dataProvider provideIsBasePathTests
- */
- public function testIsBasePath($path, $ofPath, $result)
- {
- $this->assertSame($result, Path::isBasePath($path, $ofPath));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The base path must be a string. Got: array
- */
- public function testIsBasePathFailsIfInvalidBasePath()
- {
- Path::isBasePath(array(), '/base/path');
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The path must be a string. Got: array
- */
- public function testIsBasePathFailsIfInvalidPath()
- {
- Path::isBasePath('/base/path', array());
- }
- public function provideJoinTests()
- {
- return array(
- array('', '', ''),
- array('/path/to/test', '', '/path/to/test'),
- array('/path/to//test', '', '/path/to/test'),
- array('', '/path/to/test', '/path/to/test'),
- array('', '/path/to//test', '/path/to/test'),
- array('/path/to/test', 'subdir', '/path/to/test/subdir'),
- array('/path/to/test/', 'subdir', '/path/to/test/subdir'),
- array('/path/to/test', '/subdir', '/path/to/test/subdir'),
- array('/path/to/test/', '/subdir', '/path/to/test/subdir'),
- array('/path/to/test', './subdir', '/path/to/test/subdir'),
- array('/path/to/test/', './subdir', '/path/to/test/subdir'),
- array('/path/to/test/', '../parentdir', '/path/to/parentdir'),
- array('/path/to/test', '../parentdir', '/path/to/parentdir'),
- array('path/to/test/', '/subdir', 'path/to/test/subdir'),
- array('path/to/test', '/subdir', 'path/to/test/subdir'),
- array('../path/to/test', '/subdir', '../path/to/test/subdir'),
- array('path', '../../subdir', '../subdir'),
- array('/path', '../../subdir', '/subdir'),
- array('../path', '../../subdir', '../../subdir'),
- array(array('/path/to/test', 'subdir'), '', '/path/to/test/subdir'),
- array(array('/path/to/test', '/subdir'), '', '/path/to/test/subdir'),
- array(array('/path/to/test/', 'subdir'), '', '/path/to/test/subdir'),
- array(array('/path/to/test/', '/subdir'), '', '/path/to/test/subdir'),
- array(array('/path'), '', '/path'),
- array(array('/path', 'to', '/test'), '', '/path/to/test'),
- array(array('/path', '', '/test'), '', '/path/test'),
- array(array('path', 'to', 'test'), '', 'path/to/test'),
- array(array(), '', ''),
- array('base/path', 'to/test', 'base/path/to/test'),
- array('C:\\path\\to\\test', 'subdir', 'C:/path/to/test/subdir'),
- array('C:\\path\\to\\test\\', 'subdir', 'C:/path/to/test/subdir'),
- array('C:\\path\\to\\test', '/subdir', 'C:/path/to/test/subdir'),
- array('C:\\path\\to\\test\\', '/subdir', 'C:/path/to/test/subdir'),
- array('/', 'subdir', '/subdir'),
- array('/', '/subdir', '/subdir'),
- array('C:/', 'subdir', 'C:/subdir'),
- array('C:/', '/subdir', 'C:/subdir'),
- array('C:\\', 'subdir', 'C:/subdir'),
- array('C:\\', '/subdir', 'C:/subdir'),
- array('C:', 'subdir', 'C:/subdir'),
- array('C:', '/subdir', 'C:/subdir'),
- array('phar://', '/path/to/test', 'phar:///path/to/test'),
- array('phar:///', '/path/to/test', 'phar:///path/to/test'),
- array('phar:///path/to/test', 'subdir', 'phar:///path/to/test/subdir'),
- array('phar:///path/to/test', 'subdir/', 'phar:///path/to/test/subdir'),
- array('phar:///path/to/test', '/subdir', 'phar:///path/to/test/subdir'),
- array('phar:///path/to/test/', 'subdir', 'phar:///path/to/test/subdir'),
- array('phar:///path/to/test/', '/subdir', 'phar:///path/to/test/subdir'),
- array('phar://', 'C:/path/to/test', 'phar://C:/path/to/test'),
- array('phar://', 'C:\\path\\to\\test', 'phar://C:/path/to/test'),
- array('phar://C:/path/to/test', 'subdir', 'phar://C:/path/to/test/subdir'),
- array('phar://C:/path/to/test', 'subdir/', 'phar://C:/path/to/test/subdir'),
- array('phar://C:/path/to/test', '/subdir', 'phar://C:/path/to/test/subdir'),
- array('phar://C:/path/to/test/', 'subdir', 'phar://C:/path/to/test/subdir'),
- array('phar://C:/path/to/test/', '/subdir', 'phar://C:/path/to/test/subdir'),
- array('phar://C:', 'path/to/test', 'phar://C:/path/to/test'),
- array('phar://C:', '/path/to/test', 'phar://C:/path/to/test'),
- array('phar://C:/', 'path/to/test', 'phar://C:/path/to/test'),
- array('phar://C:/', '/path/to/test', 'phar://C:/path/to/test'),
- );
- }
- /**
- * @dataProvider provideJoinTests
- */
- public function testJoin($path1, $path2, $result)
- {
- $this->assertSame($result, Path::join($path1, $path2));
- }
- public function testJoinVarArgs()
- {
- $this->assertSame('/path', Path::join('/path'));
- $this->assertSame('/path/to', Path::join('/path', 'to'));
- $this->assertSame('/path/to/test', Path::join('/path', 'to', '/test'));
- $this->assertSame('/path/to/test/subdir', Path::join('/path', 'to', '/test', 'subdir/'));
- }
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage The paths must be strings. Got: array
- */
- public function testJoinFailsIfInvalidPath()
- {
- Path::join('/path', array());
- }
- /**
- * @expectedException \RuntimeException
- * @expectedExceptionMessage Your environment or operation system isn't supported
- */
- public function testGetHomeDirectoryFailsIfNotSupportedOperationSystem()
- {
- putenv('HOME=');
- Path::getHomeDirectory();
- }
- public function testGetHomeDirectoryForUnix()
- {
- $this->assertEquals('/home/webmozart', Path::getHomeDirectory());
- }
- public function testGetHomeDirectoryForWindows()
- {
- putenv('HOME=');
- putenv('HOMEDRIVE=C:');
- putenv('HOMEPATH=/users/webmozart');
- $this->assertEquals('C:/users/webmozart', Path::getHomeDirectory());
- }
- public function testNormalize()
- {
- $this->assertSame('C:/Foo/Bar/test', Path::normalize('C:\\Foo\\Bar/test'));
- }
- /**
- * @expectedException \InvalidArgumentException
- */
- public function testNormalizeFailsIfNoString()
- {
- Path::normalize(true);
- }
- }
|