assertSame('pdf', $this->_renderer->getType()); } public function testGoodPdfResource() { $pdfResource = new Zend_Pdf(); $this->_renderer->setResource($pdfResource, 10); } /** * @expectedException Zend_Barcode_Renderer_Exception */ public function testObjectPdfResource() { $pdfResource = new StdClass(); $this->_renderer->setResource($pdfResource); } public function testDrawReturnResource() { Zend_Barcode::setBarcodeFont(dirname(__FILE__) . '/../Object/_fonts/Vera.ttf'); $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789')); $this->_renderer->setBarcode($barcode); $resource = $this->_renderer->draw(); $this->assertTrue($resource instanceof Zend_Pdf); Zend_Barcode::setBarcodeFont(''); } public function testDrawWithExistantResourceReturnResource() { Zend_Barcode::setBarcodeFont(dirname(__FILE__) . '/../Object/_fonts/Vera.ttf'); $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789')); $this->_renderer->setBarcode($barcode); $pdfResource = new Zend_Pdf(); $this->_renderer->setResource($pdfResource); $resource = $this->_renderer->draw(); $this->assertTrue($resource instanceof Zend_Pdf); $this->assertSame($resource, $pdfResource); Zend_Barcode::setBarcodeFont(''); } protected function _getRendererWithWidth500AndHeight300() { $pdf = new Zend_Pdf(); $pdf->pages[] = new Zend_Pdf_Page('500:300:'); return $this->_renderer->setResource($pdf); } public function testHorizontalPositionToCenter() { $renderer = $this->_getRendererWithWidth500AndHeight300(); $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789')); $this->assertEquals(211, $barcode->getWidth()); $renderer->setBarcode($barcode); $renderer->setHorizontalPosition('center'); $renderer->draw(); $this->assertEquals(197, $renderer->getLeftOffset()); } public function testHorizontalPositionToRight() { $renderer = $this->_getRendererWithWidth500AndHeight300(); $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789')); $this->assertEquals(211, $barcode->getWidth()); $renderer->setBarcode($barcode); $renderer->setHorizontalPosition('right'); $renderer->draw(); $this->assertEquals(394.5, $renderer->getLeftOffset()); } public function testVerticalPositionToMiddle() { $renderer = $this->_getRendererWithWidth500AndHeight300(); $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789')); $this->assertEquals(62, $barcode->getHeight()); $renderer->setBarcode($barcode); $renderer->setVerticalPosition('middle'); $renderer->draw(); $this->assertEquals(134, $renderer->getTopOffset()); } public function testVerticalPositionToBottom() { $renderer = $this->_getRendererWithWidth500AndHeight300(); $barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789')); $this->assertEquals(62, $barcode->getHeight()); $renderer->setBarcode($barcode); $renderer->setVerticalPosition('bottom'); $renderer->draw(); $this->assertEquals(269, $renderer->getTopOffset()); } }