2
0

SvgTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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-2010 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(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  23. require_once dirname(__FILE__) . '/TestCommon.php';
  24. require_once 'Zend/Barcode/Renderer/Svg.php';
  25. require_once 'Zend/Barcode/Object/Code39.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Barcode
  29. * @subpackage UnitTests
  30. * @group Zend_Barcode
  31. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Barcode_Renderer_SvgTest extends Zend_Barcode_Renderer_TestCommon
  35. {
  36. protected function _getRendererObject($options = null)
  37. {
  38. return new Zend_Barcode_Renderer_Svg($options);
  39. }
  40. public function testType()
  41. {
  42. $this->assertSame('svg', $this->_renderer->getType());
  43. }
  44. public function testGoodHeight()
  45. {
  46. $this->assertSame(0, $this->_renderer->getHeight());
  47. $this->_renderer->setHeight(123);
  48. $this->assertSame(123, $this->_renderer->getHeight());
  49. $this->_renderer->setHeight(0);
  50. $this->assertSame(0, $this->_renderer->getHeight());
  51. }
  52. /**
  53. * @expectedException Zend_Barcode_Renderer_Exception
  54. */
  55. public function testBadHeight()
  56. {
  57. $this->_renderer->setHeight(-1);
  58. }
  59. public function testGoodWidth()
  60. {
  61. $this->assertSame(0, $this->_renderer->getWidth());
  62. $this->_renderer->setWidth(123);
  63. $this->assertSame(123, $this->_renderer->getWidth());
  64. $this->_renderer->setWidth(0);
  65. $this->assertSame(0, $this->_renderer->getWidth());
  66. }
  67. /**
  68. * @expectedException Zend_Barcode_Renderer_Exception
  69. */
  70. public function testBadWidth()
  71. {
  72. $this->_renderer->setWidth(-1);
  73. }
  74. public function testGoodSvgResource()
  75. {
  76. $svgResource = new DOMDocument();
  77. $this->_renderer->setResource($svgResource, 10);
  78. }
  79. /**
  80. * @expectedException Zend_Barcode_Renderer_Exception
  81. */
  82. public function testObjectSvgResource()
  83. {
  84. $svgResource = new StdClass();
  85. $this->_renderer->setResource($svgResource);
  86. }
  87. public function testDrawReturnResource()
  88. {
  89. Zend_Barcode::setBarcodeFont(dirname(__FILE__) . '/../Object/_fonts/Vera.ttf');
  90. $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
  91. $this->_renderer->setBarcode($barcode);
  92. $resource = $this->_renderer->draw();
  93. $this->assertTrue($resource instanceof DOMDocument);
  94. Zend_Barcode::setBarcodeFont('');
  95. }
  96. public function testDrawWithExistantResourceReturnResource()
  97. {
  98. Zend_Barcode::setBarcodeFont(dirname(__FILE__) . '/../Object/_fonts/Vera.ttf');
  99. $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
  100. $this->_renderer->setBarcode($barcode);
  101. $svgResource = new DOMDocument();
  102. $rootElement = $svgResource->createElement('svg');
  103. $rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
  104. $rootElement->setAttribute('version', '1.1');
  105. $rootElement->setAttribute('width', 500);
  106. $rootElement->setAttribute('height', 300);
  107. $svgResource->appendChild($rootElement);
  108. $this->_renderer->setResource($svgResource);
  109. $resource = $this->_renderer->draw();
  110. $this->assertTrue($resource instanceof DOMDocument);
  111. $this->assertSame($resource, $svgResource);
  112. Zend_Barcode::setBarcodeFont('');
  113. }
  114. protected function _getRendererWithWidth500AndHeight300()
  115. {
  116. $svg = new DOMDocument();
  117. $rootElement = $svg->createElement('svg');
  118. $rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
  119. $rootElement->setAttribute('version', '1.1');
  120. $rootElement->setAttribute('width', 500);
  121. $rootElement->setAttribute('height', 300);
  122. $svg->appendChild($rootElement);
  123. return $this->_renderer->setResource($svg);
  124. }
  125. }