DocumentLayoutTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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;
  18. use PhpOffice\PhpPresentation\DocumentLayout;
  19. /**
  20. * Test class for DocumentLayout
  21. *
  22. * @coversDefaultClass PhpOffice\PhpPresentation\DocumentLayout
  23. */
  24. class DocumentLayoutTest extends \PHPUnit_Framework_TestCase
  25. {
  26. /**
  27. * Test create new instance
  28. */
  29. public function testConstruct()
  30. {
  31. $object = new DocumentLayout();
  32. $this->assertEquals('screen4x3', $object->getDocumentLayout());
  33. $this->assertEquals(9144000, $object->getCX());
  34. $this->assertEquals(6858000, $object->getCY());
  35. }
  36. /**
  37. * Test set custom layout
  38. */
  39. public function testSetCustomLayout()
  40. {
  41. $object = new DocumentLayout();
  42. $object->setDocumentLayout(array('cx' => 6858000, 'cy' => 9144000), false);
  43. $this->assertEquals(DocumentLayout::LAYOUT_CUSTOM, $object->getDocumentLayout());
  44. $this->assertEquals(9144000, $object->getCX());
  45. $this->assertEquals(6858000, $object->getCY());
  46. $object->setDocumentLayout(array('cx' => 6858000, 'cy' => 9144000), true);
  47. $this->assertEquals(DocumentLayout::LAYOUT_CUSTOM, $object->getDocumentLayout());
  48. $this->assertEquals(6858000, $object->getCX());
  49. $this->assertEquals(9144000, $object->getCY());
  50. }
  51. public function testCX()
  52. {
  53. $value = rand(1, 100000);
  54. $object = new DocumentLayout();
  55. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCX($value));
  56. $this->assertEquals($value, $object->getCX());
  57. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCX($value, DocumentLayout::UNIT_CENTIMETER));
  58. $this->assertEquals($value, $object->getCX(DocumentLayout::UNIT_CENTIMETER));
  59. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCX($value, DocumentLayout::UNIT_EMU));
  60. $this->assertEquals($value, $object->getCX(DocumentLayout::UNIT_EMU));
  61. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCX($value, DocumentLayout::UNIT_INCH));
  62. $this->assertEquals($value, $object->getCX(DocumentLayout::UNIT_INCH));
  63. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCX($value, DocumentLayout::UNIT_MILLIMETER));
  64. $this->assertEquals($value, $object->getCX(DocumentLayout::UNIT_MILLIMETER));
  65. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCX($value, DocumentLayout::UNIT_POINT));
  66. $this->assertEquals($value, $object->getCX(DocumentLayout::UNIT_POINT));
  67. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCX($value, DocumentLayout::UNIT_PIXEL));
  68. $this->assertEquals($value, $object->getCX(DocumentLayout::UNIT_PIXEL));
  69. }
  70. public function testCY()
  71. {
  72. $value = rand(1, 100000);
  73. $object = new DocumentLayout();
  74. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCY($value));
  75. $this->assertEquals($value, $object->getCY());
  76. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCY($value, DocumentLayout::UNIT_CENTIMETER));
  77. $this->assertEquals($value, $object->getCY(DocumentLayout::UNIT_CENTIMETER));
  78. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCY($value, DocumentLayout::UNIT_EMU));
  79. $this->assertEquals($value, $object->getCY(DocumentLayout::UNIT_EMU));
  80. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCY($value, DocumentLayout::UNIT_INCH));
  81. $this->assertEquals($value, $object->getCY(DocumentLayout::UNIT_INCH));
  82. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCY($value, DocumentLayout::UNIT_MILLIMETER));
  83. $this->assertEquals($value, $object->getCY(DocumentLayout::UNIT_MILLIMETER));
  84. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCY($value, DocumentLayout::UNIT_POINT));
  85. $this->assertEquals($value, $object->getCY(DocumentLayout::UNIT_POINT));
  86. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentLayout', $object->setCY($value, DocumentLayout::UNIT_PIXEL));
  87. $this->assertEquals($value, $object->getCY(DocumentLayout::UNIT_PIXEL));
  88. }
  89. }