SvgTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 testGoodSvgResource()
  45. {
  46. $svgResource = new DOMDocument();
  47. $this->_renderer->setResource($svgResource, 10);
  48. }
  49. /**
  50. * @expectedException Zend_Barcode_Renderer_Exception
  51. */
  52. public function testObjectSvgResource()
  53. {
  54. $svgResource = new StdClass();
  55. $this->_renderer->setResource($svgResource);
  56. }
  57. public function testDrawReturnResource()
  58. {
  59. Zend_Barcode::setBarcodeFont(dirname(__FILE__) . '/../Object/_fonts/Vera.ttf');
  60. $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
  61. $this->_renderer->setBarcode($barcode);
  62. $resource = $this->_renderer->draw();
  63. $this->assertTrue($resource instanceof DOMDocument);
  64. Zend_Barcode::setBarcodeFont('');
  65. }
  66. public function testDrawWithExistantResourceReturnResource()
  67. {
  68. Zend_Barcode::setBarcodeFont(dirname(__FILE__) . '/../Object/_fonts/Vera.ttf');
  69. $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
  70. $this->_renderer->setBarcode($barcode);
  71. $svgResource = new DOMDocument();
  72. $rootElement = $svgResource->createElement('svg');
  73. $rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
  74. $rootElement->setAttribute('version', '1.1');
  75. $rootElement->setAttribute('width', 500);
  76. $rootElement->setAttribute('height', 300);
  77. $svgResource->appendChild($rootElement);
  78. $this->_renderer->setResource($svgResource);
  79. $resource = $this->_renderer->draw();
  80. $this->assertTrue($resource instanceof DOMDocument);
  81. $this->assertSame($resource, $svgResource);
  82. Zend_Barcode::setBarcodeFont('');
  83. }
  84. protected function _getRendererWithWidth500AndHeight300()
  85. {
  86. $svg = new DOMDocument();
  87. $rootElement = $svg->createElement('svg');
  88. $rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
  89. $rootElement->setAttribute('version', '1.1');
  90. $rootElement->setAttribute('width', 500);
  91. $rootElement->setAttribute('height', 300);
  92. $svg->appendChild($rootElement);
  93. return $this->_renderer->setResource($svg);
  94. }
  95. }