FileTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * This file is part of PHPOffice Common
  4. *
  5. * PHPOffice Common is free software distributed under the terms of the GNU Lesser
  6. * General Public License version 3 as published by the Free Software Foundation.
  7. *
  8. * For the full copyright and license information, please read the LICENSE
  9. * file that was distributed with this source code. For the full list of
  10. * contributors, visit https://github.com/PHPOffice/Common/contributors.
  11. *
  12. * @link https://github.com/PHPOffice/Common
  13. * @copyright 2009-2016 PHPOffice Common contributors
  14. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  15. */
  16. namespace PhpOffice\Common\Tests;
  17. use PhpOffice\Common\File;
  18. /**
  19. * Test class for File
  20. *
  21. * @coversDefaultClass PhpOffice\Common\File
  22. */
  23. class FileTest extends \PHPUnit\Framework\TestCase
  24. {
  25. /**
  26. */
  27. public function testFileExists()
  28. {
  29. $pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR;
  30. $this->assertTrue(File::fileExists($pathResources.'images'.DIRECTORY_SEPARATOR.'PHPPowerPointLogo.png'));
  31. $this->assertFalse(File::fileExists($pathResources.'images'.DIRECTORY_SEPARATOR.'PHPPowerPointLogo_404.png'));
  32. $this->assertTrue(File::fileExists('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#[Content_Types].xml'));
  33. $this->assertFalse(File::fileExists('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#404.xml'));
  34. $this->assertFalse(File::fileExists('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'404.pptx#404.xml'));
  35. }
  36. /**
  37. */
  38. public function testGetFileContents()
  39. {
  40. $pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR;
  41. $this->assertInternalType('string', File::fileGetContents($pathResources.'images'.DIRECTORY_SEPARATOR.'PHPPowerPointLogo.png'));
  42. $this->assertFalse(File::fileGetContents($pathResources.'images'.DIRECTORY_SEPARATOR.'PHPPowerPointLogo_404.png'));
  43. $this->assertInternalType('string', File::fileGetContents('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#[Content_Types].xml'));
  44. $this->assertFalse(File::fileGetContents('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#404.xml'));
  45. $this->assertFalse(File::fileGetContents('zip://'.$pathResources.'files'.DIRECTORY_SEPARATOR.'404.pptx#404.xml'));
  46. }
  47. /**
  48. */
  49. public function testRealPath()
  50. {
  51. $pathFiles = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR;
  52. $this->assertEquals($pathFiles.'Sample_01_Simple.pptx', File::realpath($pathFiles.'Sample_01_Simple.pptx'));
  53. $this->assertEquals('zip://'.$pathFiles.'Sample_01_Simple.pptx#[Content_Types].xml', File::realpath('zip://'.$pathFiles.'Sample_01_Simple.pptx#[Content_Types].xml'));
  54. $this->assertEquals('zip://'.$pathFiles.'Sample_01_Simple.pptx#/[Content_Types].xml', File::realpath('zip://'.$pathFiles.'Sample_01_Simple.pptx#/rels/../[Content_Types].xml'));
  55. }
  56. }