FileLoaderTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Routing\Loader;
  11. use Symfony\Component\Routing\Loader\FileLoader;
  12. class FileLoaderTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @covers Symfony\Component\Routing\Loader\FileLoader::__construct
  16. */
  17. public function testConstructor()
  18. {
  19. $loader = new ProjectLoader(__DIR__);
  20. $this->assertEquals(array(__DIR__), $loader->paths, '__construct() takes a path as its second argument');
  21. $loader = new ProjectLoader(array(__DIR__, __DIR__));
  22. $this->assertEquals(array(__DIR__, __DIR__), $loader->paths, '__construct() takes an array of paths as its second argument');
  23. }
  24. /**
  25. * @covers Symfony\Component\Routing\Loader\FileLoader::GetAbsolutePath
  26. * @covers Symfony\Component\Routing\Loader\FileLoader::isAbsolutePath
  27. */
  28. public function testGetAbsolutePath()
  29. {
  30. $loader = new ProjectLoader(array(__DIR__.'/../Fixtures'));
  31. $this->assertEquals('/foo.xml', $loader->getAbsolutePath('/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  32. $this->assertEquals('c:\\\\foo.xml', $loader->getAbsolutePath('c:\\\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  33. $this->assertEquals('c:/foo.xml', $loader->getAbsolutePath('c:/foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  34. $this->assertEquals('\\server\\foo.xml', $loader->getAbsolutePath('\\server\\foo.xml'), '->getAbsolutePath() return the path unmodified if it is already an absolute path');
  35. $this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'FileLoaderTest.php', $loader->getAbsolutePath('FileLoaderTest.php', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in the current path');
  36. $this->assertEquals(__DIR__.'/../Fixtures'.DIRECTORY_SEPARATOR.'foo.xml', $loader->getAbsolutePath('foo.xml', __DIR__), '->getAbsolutePath() returns an absolute filename if the file exists in one of the paths given in the constructor');
  37. $this->assertEquals('foobar.xml', $loader->getAbsolutePath('foobar.xml', __DIR__), '->getAbsolutePath() returns the path unmodified if it is unable to find it in the given paths');
  38. }
  39. }
  40. class ProjectLoader extends FileLoader
  41. {
  42. public $paths;
  43. public function load($resource, $type = null)
  44. {
  45. }
  46. public function supports($resource, $type = null)
  47. {
  48. return true;
  49. }
  50. public function getType()
  51. {
  52. }
  53. public function getAbsolutePath($file, $currentPath = null)
  54. {
  55. return parent::getAbsolutePath($file, $currentPath);
  56. }
  57. }