PageRenderTime 61ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/PhpWord/Tests/Element/ListItemRunTest.php

https://github.com/cyrillkalita/PHPWord
PHP | 175 lines | 93 code | 26 blank | 56 comment | 0 complexity | 51c0ce0e2be9ab41589a006e2a57fda6 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord 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/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Tests\Element;
  18. use PhpOffice\PhpWord\Element\ListItemRun;
  19. use PhpOffice\PhpWord\PhpWord;
  20. /**
  21. * Test class for PhpOffice\PhpWord\Element\ListItemRun
  22. *
  23. * @runTestsInSeparateProcesses
  24. */
  25. class ListItemRunTest extends \PHPUnit_Framework_TestCase
  26. {
  27. /**
  28. * New instance
  29. */
  30. public function testConstructNull()
  31. {
  32. $oListItemRun = new ListItemRun();
  33. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
  34. $this->assertCount(0, $oListItemRun->getElements());
  35. $this->assertEquals($oListItemRun->getParagraphStyle(), null);
  36. }
  37. /**
  38. * New instance with string
  39. */
  40. public function testConstructString()
  41. {
  42. $oListItemRun = new ListItemRun(0, null, 'pStyle');
  43. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
  44. $this->assertCount(0, $oListItemRun->getElements());
  45. $this->assertEquals($oListItemRun->getParagraphStyle(), 'pStyle');
  46. }
  47. /**
  48. * New instance with string
  49. */
  50. public function testConstructListString()
  51. {
  52. $oListItemRun = new ListItemRun(0, 'numberingStyle');
  53. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
  54. $this->assertCount(0, $oListItemRun->getElements());
  55. }
  56. /**
  57. * New instance with array
  58. */
  59. public function testConstructArray()
  60. {
  61. $oListItemRun = new ListItemRun(0, null, array('spacing' => 100));
  62. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
  63. $this->assertCount(0, $oListItemRun->getElements());
  64. $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oListItemRun->getParagraphStyle());
  65. }
  66. /**
  67. * Get style
  68. */
  69. public function testStyle()
  70. {
  71. $oListItemRun = new ListItemRun(1, array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER));
  72. $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItemRun->getStyle());
  73. $this->assertEquals($oListItemRun->getStyle()->getListType(), \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER);
  74. }
  75. /**
  76. * getDepth
  77. */
  78. public function testDepth()
  79. {
  80. $iVal = rand(1, 1000);
  81. $oListItemRun = new ListItemRun($iVal);
  82. $this->assertEquals($oListItemRun->getDepth(), $iVal);
  83. }
  84. /**
  85. * Add text
  86. */
  87. public function testAddText()
  88. {
  89. $oListItemRun = new ListItemRun();
  90. $element = $oListItemRun->addText('text');
  91. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
  92. $this->assertCount(1, $oListItemRun->getElements());
  93. $this->assertEquals($element->getText(), 'text');
  94. }
  95. /**
  96. * Add text non-UTF8
  97. */
  98. public function testAddTextNotUTF8()
  99. {
  100. $oListItemRun = new ListItemRun();
  101. $element = $oListItemRun->addText(utf8_decode('ééé'));
  102. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
  103. $this->assertCount(1, $oListItemRun->getElements());
  104. $this->assertEquals($element->getText(), 'ééé');
  105. }
  106. /**
  107. * Add link
  108. */
  109. public function testAddLink()
  110. {
  111. $oListItemRun = new ListItemRun();
  112. $element = $oListItemRun->addLink('http://www.google.fr');
  113. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
  114. $this->assertCount(1, $oListItemRun->getElements());
  115. $this->assertEquals($element->getTarget(), 'http://www.google.fr');
  116. }
  117. /**
  118. * Add link with name
  119. */
  120. public function testAddLinkWithName()
  121. {
  122. $oListItemRun = new ListItemRun();
  123. $element = $oListItemRun->addLink('http://www.google.fr', utf8_decode('ééé'));
  124. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
  125. $this->assertCount(1, $oListItemRun->getElements());
  126. $this->assertEquals($element->getTarget(), 'http://www.google.fr');
  127. $this->assertEquals($element->getText(), 'ééé');
  128. }
  129. /**
  130. * Add text break
  131. */
  132. public function testAddTextBreak()
  133. {
  134. $oListItemRun = new ListItemRun();
  135. $oListItemRun->addTextBreak(2);
  136. $this->assertCount(2, $oListItemRun->getElements());
  137. }
  138. /**
  139. * Add image
  140. */
  141. public function testAddImage()
  142. {
  143. $src = __DIR__ . "/../_files/images/earth.jpg";
  144. $oListItemRun = new ListItemRun();
  145. $element = $oListItemRun->addImage($src);
  146. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
  147. $this->assertCount(1, $oListItemRun->getElements());
  148. }
  149. }