PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/PhpWord/Tests/Element/LinkTest.php

https://github.com/cyrillkalita/PHPWord
PHP | 86 lines | 43 code | 10 blank | 33 comment | 0 complexity | ad9e79ce634b705541186122a7737772 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\Link;
  19. use PhpOffice\PhpWord\Style\Font;
  20. /**
  21. * Test class for PhpOffice\PhpWord\Element\Link
  22. *
  23. * @coversDefaultClass \PhpOffice\PhpWord\Element\Link
  24. * @runTestsInSeparateProcesses
  25. */
  26. class LinkTest extends \PHPUnit_Framework_TestCase
  27. {
  28. /**
  29. * Create new instance
  30. */
  31. public function testConstructDefault()
  32. {
  33. $oLink = new Link('http://www.google.com');
  34. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
  35. $this->assertEquals($oLink->getTarget(), 'http://www.google.com');
  36. $this->assertEquals($oLink->getText(), $oLink->getTarget());
  37. $this->assertEquals($oLink->getFontStyle(), null);
  38. $this->assertEquals($oLink->getParagraphStyle(), null);
  39. }
  40. /**
  41. * Create new instance with array
  42. */
  43. public function testConstructWithParamsArray()
  44. {
  45. $oLink = new Link(
  46. 'http://www.google.com',
  47. 'Search Engine',
  48. array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE),
  49. array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
  50. );
  51. $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
  52. $this->assertEquals($oLink->getTarget(), 'http://www.google.com');
  53. $this->assertEquals($oLink->getText(), 'Search Engine');
  54. $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle());
  55. $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle());
  56. }
  57. /**
  58. * Create new instance with style name string
  59. */
  60. public function testConstructWithParamsString()
  61. {
  62. $oLink = new Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle');
  63. $this->assertEquals($oLink->getFontStyle(), 'fontStyle');
  64. $this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle');
  65. }
  66. /**
  67. * Set/get relation Id
  68. */
  69. public function testRelationId()
  70. {
  71. $oLink = new Link('http://www.google.com');
  72. $iVal = rand(1, 1000);
  73. $oLink->setRelationId($iVal);
  74. $this->assertEquals($oLink->getRelationId(), $iVal);
  75. }
  76. }