SerializedTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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\Writer;
  18. use PhpOffice\PhpPresentation\Writer\Serialized;
  19. use PhpOffice\PhpPresentation\PhpPresentation;
  20. /**
  21. * Test class for serialized reader
  22. *
  23. * @coversDefaultClass PhpOffice\PhpPresentation\Reader\Serialized
  24. */
  25. class SerializedTest extends \PHPUnit_Framework_TestCase
  26. {
  27. public function testConstruct()
  28. {
  29. $object = new Serialized(new PhpPresentation());
  30. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $object->getPhpPresentation());
  31. }
  32. /**
  33. * @expectedException \Exception
  34. * @expectedExceptionMessage No PhpPresentation assigned.
  35. */
  36. public function testEmptyConstruct()
  37. {
  38. $object = new Serialized();
  39. $object->getPhpPresentation();
  40. }
  41. /**
  42. * @expectedException \Exception
  43. * @expectedExceptionMessage Filename is empty.
  44. */
  45. public function testSaveEmpty()
  46. {
  47. $object = new Serialized(new PhpPresentation());
  48. $object->save('');
  49. }
  50. /**
  51. * @expectedException \Exception
  52. * @expectedExceptionMessage No PhpPresentation assigned.
  53. */
  54. public function testSaveNoObject()
  55. {
  56. $object = new Serialized();
  57. $object->save('file.phpppt');
  58. }
  59. public function testSave()
  60. {
  61. $oPhpPresentation = new PhpPresentation();
  62. $oSlide = $oPhpPresentation->getActiveSlide();
  63. $oImage = $oSlide->createDrawingShape();
  64. $oImage->setPath(PHPPRESENTATION_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'PhpPresentationLogo.png');
  65. $object = new Serialized($oPhpPresentation);
  66. $file = tempnam(sys_get_temp_dir(), 'PhpPresentation_Serialized');
  67. $this->assertFileExists($file, $object->save($file));
  68. }
  69. /**
  70. * @expectedException \Exception
  71. * @expectedExceptionMessage Could not open
  72. */
  73. public function testSaveNotExistingDir()
  74. {
  75. $oPhpPresentation = new PhpPresentation();
  76. $oSlide = $oPhpPresentation->getActiveSlide();
  77. $oImage = $oSlide->createDrawingShape();
  78. $oImage->setPath(PHPPRESENTATION_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'PhpPresentationLogo.png');
  79. $object = new Serialized($oPhpPresentation);
  80. $file = tempnam(sys_get_temp_dir(), 'PhpPresentation_Serialized');
  81. $this->assertFileExists($file, $object->save($file.DIRECTORY_SEPARATOR.'test'.DIRECTORY_SEPARATOR.'test'));
  82. }
  83. public function testSaveOverwriting()
  84. {
  85. $oPhpPresentation = new PhpPresentation();
  86. $oSlide = $oPhpPresentation->getActiveSlide();
  87. $oImage = $oSlide->createDrawingShape();
  88. $oImage->setPath(PHPPRESENTATION_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'PhpPresentationLogo.png');
  89. $object = new Serialized($oPhpPresentation);
  90. $file = tempnam(sys_get_temp_dir(), 'PhpPresentation_Serialized');
  91. file_put_contents($file, rand(1, 100));
  92. $this->assertFileExists($file, $object->save($file));
  93. }
  94. }