ZipFileTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * This file is part of PHPPresentation - A pure PHP library for reading and writing
  4. * presentations documents.
  5. *
  6. * PHPPresentation is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
  12. *
  13. * @copyright 2009-2015 PHPPresentation contributors
  14. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  15. * @link https://github.com/PHPOffice/PHPPresentation
  16. */
  17. namespace PhpOffice\PhpPresentation\Tests\Shape\Drawing;
  18. use PhpOffice\PhpPresentation\Shape\Drawing\ZipFile;
  19. /**
  20. * Test class for Drawing element
  21. *
  22. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\Drawing
  23. */
  24. class ZipFileTest extends \PHPUnit_Framework_TestCase
  25. {
  26. protected $fileOk;
  27. protected $fileKoZip;
  28. protected $fileKoFile;
  29. public function setUp()
  30. {
  31. parent::setUp();
  32. DrawingTest::$getimagesizefromstringExists = true;
  33. $this->fileOk = 'zip://'.PHPPRESENTATION_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#ppt/media/phppowerpoint_logo1.gif';
  34. $this->fileKoZip = 'zip://'.PHPPRESENTATION_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'fileNotExist.pptx#ppt/media/phppowerpoint_logo1.gif';
  35. $this->fileKoFile = 'zip://'.PHPPRESENTATION_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'Sample_01_Simple.pptx#ppt/media/filenotexists.gif';
  36. }
  37. /**
  38. * @expectedException \Exception
  39. * @expectedExceptionMessage fileNotExist.pptx does not exist
  40. */
  41. public function testContentsException()
  42. {
  43. $oDrawing = new ZipFile();
  44. $oDrawing->setPath($this->fileKoZip);
  45. $oDrawing->getContents();
  46. }
  47. public function testExtension()
  48. {
  49. $oDrawing = new ZipFile();
  50. $oDrawing->setPath($this->fileOk);
  51. $this->assertEquals('gif', $oDrawing->getExtension());
  52. }
  53. /**
  54. * @requires PHP 5.4
  55. */
  56. public function testMimeType()
  57. {
  58. $oDrawing = new ZipFile();
  59. $oDrawing->setPath($this->fileOk);
  60. $this->assertEquals('image/gif', $oDrawing->getMimeType());
  61. }
  62. /**
  63. * @requires PHP 5.4
  64. */
  65. public function testMimeTypeFunctionNotExists()
  66. {
  67. DrawingTest::$getimagesizefromstringExists = false;
  68. $oDrawing = new ZipFile();
  69. $oDrawing->setPath($this->fileOk);
  70. $this->assertEquals('image/gif', $oDrawing->getMimeType());
  71. }
  72. }