You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

templatelayout.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Test;
  9. /**
  10. * @package OC\Test
  11. */
  12. class OC_TemplateLayout extends \Test\TestCase {
  13. private $oldServerURI;
  14. private $oldScriptName;
  15. protected function setUp() {
  16. parent::setUp();
  17. $this->oldServerURI = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
  18. $this->oldScriptName = $_SERVER['SCRIPT_NAME'];
  19. }
  20. protected function tearDown() {
  21. if ($this->oldServerURI === null) {
  22. unset($_SERVER['REQUEST_URI']);
  23. } else {
  24. $_SERVER['REQUEST_URI'] = $this->oldServerURI;
  25. }
  26. $_SERVER['SCRIPT_NAME'] = $this->oldScriptName;
  27. parent::tearDown();
  28. }
  29. /**
  30. * Contains valid file paths in the scheme array($absolutePath, $expectedPath)
  31. * @return array
  32. */
  33. public function validFilePathProvider() {
  34. return array(
  35. array(\OC::$SERVERROOT . '/apps/files/js/fancyJS.js', '/apps/files/js/fancyJS.js'),
  36. array(\OC::$SERVERROOT. '/test.js', '/test.js'),
  37. array(\OC::$SERVERROOT . '/core/test.js', '/core/test.js'),
  38. array(\OC::$SERVERROOT, ''),
  39. );
  40. }
  41. /**
  42. * @dataProvider validFilePathProvider
  43. */
  44. public function testConvertToRelativePath($absolutePath, $expected) {
  45. $_SERVER['REQUEST_URI'] = $expected;
  46. $_SERVER['SCRIPT_NAME'] = '/';
  47. $relativePath = \Test_Helper::invokePrivate(new \OC_TemplateLayout('user'), 'convertToRelativePath', array($absolutePath));
  48. $this->assertEquals($expected, $relativePath);
  49. }
  50. /**
  51. * @expectedException \Exception
  52. * @expectedExceptionMessage $filePath is not under the \OC::$SERVERROOT
  53. */
  54. public function testInvalidConvertToRelativePath() {
  55. $invalidFile = '/this/file/is/invalid';
  56. $_SERVER['REQUEST_URI'] = $invalidFile;
  57. $_SERVER['SCRIPT_NAME'] = '/';
  58. \Test_Helper::invokePrivate(new \OC_TemplateLayout('user'), 'convertToRelativePath', array($invalidFile));
  59. }
  60. }