2
0

SvgTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Barcode
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: SvgTest.php 20096 2010-01-06 02:05:09Z bkarwin $
  21. */
  22. require_once dirname(__FILE__) . '/TestCommon.php';
  23. require_once 'Zend/Barcode/Renderer/Svg.php';
  24. require_once 'Zend/Barcode/Object/Code39.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Barcode
  28. * @subpackage UnitTests
  29. * @group Zend_Barcode
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Barcode_Renderer_SvgTest extends Zend_Barcode_Renderer_TestCommon
  34. {
  35. protected function _getRendererObject($options = null)
  36. {
  37. return new Zend_Barcode_Renderer_Svg($options);
  38. }
  39. public function testType()
  40. {
  41. $this->assertSame('svg', $this->_renderer->getType());
  42. }
  43. public function testGoodHeight()
  44. {
  45. $this->assertSame(0, $this->_renderer->getHeight());
  46. $this->_renderer->setHeight(123);
  47. $this->assertSame(123, $this->_renderer->getHeight());
  48. $this->_renderer->setHeight(0);
  49. $this->assertSame(0, $this->_renderer->getHeight());
  50. }
  51. /**
  52. * @expectedException Zend_Barcode_Renderer_Exception
  53. */
  54. public function testBadHeight()
  55. {
  56. $this->_renderer->setHeight(-1);
  57. }
  58. public function testGoodWidth()
  59. {
  60. $this->assertSame(0, $this->_renderer->getWidth());
  61. $this->_renderer->setWidth(123);
  62. $this->assertSame(123, $this->_renderer->getWidth());
  63. $this->_renderer->setWidth(0);
  64. $this->assertSame(0, $this->_renderer->getWidth());
  65. }
  66. /**
  67. * @expectedException Zend_Barcode_Renderer_Exception
  68. */
  69. public function testBadWidth()
  70. {
  71. $this->_renderer->setWidth(-1);
  72. }
  73. public function testGoodSvgResource()
  74. {
  75. $svgResource = new DOMDocument();
  76. $this->_renderer->setResource($svgResource, 10);
  77. }
  78. /**
  79. * @expectedException Zend_Barcode_Renderer_Exception
  80. */
  81. public function testObjectSvgResource()
  82. {
  83. $svgResource = new StdClass();
  84. $this->_renderer->setResource($svgResource);
  85. }
  86. public function testDrawReturnResource()
  87. {
  88. Zend_Barcode::setBarcodeFont(dirname(__FILE__) . '/../Object/_fonts/Vera.ttf');
  89. $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
  90. $this->_renderer->setBarcode($barcode);
  91. $resource = $this->_renderer->draw();
  92. $this->assertTrue($resource instanceof DOMDocument);
  93. Zend_Barcode::setBarcodeFont('');
  94. }
  95. public function testDrawWithExistantResourceReturnResource()
  96. {
  97. Zend_Barcode::setBarcodeFont(dirname(__FILE__) . '/../Object/_fonts/Vera.ttf');
  98. $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
  99. $this->_renderer->setBarcode($barcode);
  100. $svgResource = new DOMDocument();
  101. $rootElement = $svgResource->createElement('svg');
  102. $rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
  103. $rootElement->setAttribute('version', '1.1');
  104. $rootElement->setAttribute('width', 500);
  105. $rootElement->setAttribute('height', 300);
  106. $svgResource->appendChild($rootElement);
  107. $this->_renderer->setResource($svgResource);
  108. $resource = $this->_renderer->draw();
  109. $this->assertTrue($resource instanceof DOMDocument);
  110. $this->assertSame($resource, $svgResource);
  111. Zend_Barcode::setBarcodeFont('');
  112. }
  113. protected function _getRendererWithWidth500AndHeight300()
  114. {
  115. $svg = new DOMDocument();
  116. $rootElement = $svg->createElement('svg');
  117. $rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
  118. $rootElement->setAttribute('version', '1.1');
  119. $rootElement->setAttribute('width', 500);
  120. $rootElement->setAttribute('height', 300);
  121. $svg->appendChild($rootElement);
  122. return $this->_renderer->setResource($svg);
  123. }
  124. }