No Description

SettingsTest.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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;
  18. use PhpOffice\PhpWord\Settings;
  19. /**
  20. * Test class for PhpOffice\PhpWord\Settings
  21. *
  22. * @coversDefaultClass \PhpOffice\PhpWord\Settings
  23. * @runTestsInSeparateProcesses
  24. */
  25. class SettingsTest extends \PHPUnit_Framework_TestCase
  26. {
  27. /**
  28. * Test set/get compatibity option
  29. */
  30. public function testSetGetCompatibility()
  31. {
  32. $this->assertTrue(Settings::hasCompatibility());
  33. $this->assertTrue(Settings::setCompatibility(false));
  34. $this->assertFalse(Settings::hasCompatibility());
  35. }
  36. /**
  37. * Test set/get zip class
  38. */
  39. public function testSetGetZipClass()
  40. {
  41. $this->assertEquals(Settings::ZIPARCHIVE, Settings::getZipClass());
  42. $this->assertTrue(Settings::setZipClass(Settings::PCLZIP));
  43. $this->assertFalse(Settings::setZipClass('foo'));
  44. }
  45. /**
  46. * Test set/get PDF renderer
  47. */
  48. public function testSetGetPdfRenderer()
  49. {
  50. $domPdfPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
  51. $this->assertFalse(Settings::setPdfRenderer('FOO', 'dummy/path'));
  52. $this->assertTrue(Settings::setPdfRenderer(Settings::PDF_RENDERER_DOMPDF, $domPdfPath));
  53. $this->assertEquals(Settings::PDF_RENDERER_DOMPDF, Settings::getPdfRendererName());
  54. $this->assertEquals($domPdfPath, Settings::getPdfRendererPath());
  55. $this->assertFalse(Settings::setPdfRendererPath('dummy/path'));
  56. }
  57. /**
  58. * Test set/get measurement unit
  59. */
  60. public function testSetGetMeasurementUnit()
  61. {
  62. $this->assertEquals(Settings::UNIT_TWIP, Settings::getMeasurementUnit());
  63. $this->assertTrue(Settings::setMeasurementUnit(Settings::UNIT_INCH));
  64. $this->assertFalse(Settings::setMeasurementUnit('foo'));
  65. }
  66. /**
  67. * @covers ::getTempDir
  68. * @test
  69. */
  70. public function testPhpTempDirIsUsedByDefault()
  71. {
  72. $this->assertEquals(sys_get_temp_dir(), Settings::getTempDir());
  73. }
  74. /**
  75. * @covers ::setTempDir
  76. * @covers ::getTempDir
  77. * @depends testPhpTempDirIsUsedByDefault
  78. * @test
  79. */
  80. public function testTempDirCanBeSet()
  81. {
  82. $userDefinedTempDir = 'C:\PhpWordTemp';
  83. Settings::setTempDir($userDefinedTempDir);
  84. $currentTempDir = Settings::getTempDir();
  85. $this->assertEquals($userDefinedTempDir, $currentTempDir);
  86. $this->assertNotEquals(sys_get_temp_dir(), $currentTempDir);
  87. }
  88. /**
  89. * Test set/get default font name
  90. */
  91. public function testSetGetDefaultFontName()
  92. {
  93. $this->assertEquals(Settings::DEFAULT_FONT_NAME, Settings::getDefaultFontName());
  94. $this->assertTrue(Settings::setDefaultFontName('Times New Roman'));
  95. $this->assertFalse(Settings::setDefaultFontName(' '));
  96. }
  97. /**
  98. * Test set/get default font size
  99. */
  100. public function testSetGetDefaultFontSize()
  101. {
  102. $this->assertEquals(Settings::DEFAULT_FONT_SIZE, Settings::getDefaultFontSize());
  103. $this->assertTrue(Settings::setDefaultFontSize(12));
  104. $this->assertFalse(Settings::setDefaultFontSize(null));
  105. }
  106. /**
  107. * Test load config
  108. */
  109. public function testLoadConfig()
  110. {
  111. $expected = array(
  112. 'compatibility' => true,
  113. 'zipClass' => 'ZipArchive',
  114. 'pdfRendererName' => 'DomPDF',
  115. 'pdfRendererPath' => '',
  116. 'defaultFontName' => 'Arial',
  117. 'defaultFontSize' => 10,
  118. );
  119. // Test default value
  120. $this->assertEquals($expected, Settings::loadConfig());
  121. // Test with valid file
  122. $this->assertEquals($expected, Settings::loadConfig(__DIR__ . '/../../../phpword.ini.dist'));
  123. // Test with invalid file
  124. $this->assertEmpty(Settings::loadConfig(__DIR__ . '/../../../phpunit.xml.dist'));
  125. }
  126. }