RowTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\Table;
  18. use PhpOffice\PhpPresentation\Shape\Table\Row;
  19. use PhpOffice\PhpPresentation\Style\Fill;
  20. /**
  21. * Test class for Row element
  22. *
  23. * @coversDefaultClass PhpOffice\PhpPresentation\Shape\Row
  24. */
  25. class RowTest extends \PHPUnit_Framework_TestCase
  26. {
  27. /**
  28. * Test can read
  29. */
  30. public function testConstruct()
  31. {
  32. $object = new Row();
  33. $this->assertCount(1, $object->getCells());
  34. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  35. $value = rand(1, 100);
  36. $object = new Row($value);
  37. $this->assertCount($value, $object->getCells());
  38. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  39. }
  40. public function testGetCell()
  41. {
  42. $object = new Row();
  43. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Table\\Cell', $object->getCell(0));
  44. $this->assertNull($object->getCell(1000, true));
  45. }
  46. /**
  47. * @expectedException \Exception
  48. * expectedExceptionMessage Cell number out of bounds.
  49. */
  50. public function testGetCellException()
  51. {
  52. $object = new Row();
  53. $object->getCell(1);
  54. }
  55. public function testNextCell()
  56. {
  57. $object = new Row(2);
  58. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Table\\Cell', $object->nextCell());
  59. }
  60. /**
  61. * @expectedException \Exception
  62. * expectedExceptionMessage Cell count out of bounds.
  63. */
  64. public function testNextCellException()
  65. {
  66. $object = new Row();
  67. $object->nextCell();
  68. $object->nextCell();
  69. }
  70. /**
  71. * Test get/set hash index
  72. */
  73. public function testSetGetHashIndex()
  74. {
  75. $object = new Row();
  76. $value = rand(1, 100);
  77. $object->setHashIndex($value);
  78. $this->assertEquals($value, $object->getHashIndex());
  79. }
  80. public function testGetSetFill()
  81. {
  82. $object = new Row();
  83. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Table\\Row', $object->setFill(new Fill()));
  84. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getFill());
  85. }
  86. public function testGetSetHeight()
  87. {
  88. $object = new Row();
  89. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Table\\Row', $object->setHeight());
  90. $this->assertEquals(0, $object->getHeight());
  91. $value = rand(1, 100);
  92. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Table\\Row', $object->setHeight($value));
  93. $this->assertEquals($value, $object->getHeight());
  94. }
  95. }