* @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode * * This file is part of tc-lib-barcode software library. */ namespace Test; /** * Barcode class test * * @since 2015-02-21 * @category Library * @package Barcode * @author Nicola Asuni * @copyright 2015-2015 Nicola Asuni - Tecnick.com LTD * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode */ class BarcodeTest extends \PHPUnit_Framework_TestCase { protected $obj = null; public function setUp() { //$this->markTestSkipped(); // skip this test $this->obj = new \Com\Tecnick\Barcode\Barcode; } public function testGetTypes() { $types = $this->obj->getTypes(); $this->assertEquals(36, count($types)); } public function testGetBarcodeObjException() { $this->setExpectedException('\Com\Tecnick\Barcode\Exception'); $this->obj->getBarcodeObj( 'ERROR', '01001100011100001111,10110011100011110000', -2, -2, 'purple' ); } public function testSetPaddingException() { $this->setExpectedException('\Com\Tecnick\Barcode\Exception'); $this->obj->getBarcodeObj( 'LRAW,AB,12,E3F', '01001100011100001111,10110011100011110000', -2, -2, 'purple', array(10) ); } public function testEmptyColumns() { $this->setExpectedException('\Com\Tecnick\Barcode\Exception'); $this->obj->getBarcodeObj('LRAW', ''); } public function testEmptyInput() { $this->setExpectedException('\Com\Tecnick\Barcode\Exception'); $this->obj->getBarcodeObj('LRAW', array()); } public function testSpotColor() { $bobj = $this->obj->getBarcodeObj( 'LRAW', '01001100011100001111,10110011100011110000', -2, -2, 'all', array(-2, 3, 0, 1) ); $this->assertEquals('#000000ff', $bobj->getArray()['color_obj']->getRgbaHexColor()); $this->assertNUll($bobj->getArray()['bg_color_obj']); } public function testBackgroundColor() { $bobj = $this->obj->getBarcodeObj( 'LRAW', '01001100011100001111,10110011100011110000', -2, -2, 'all', array(-2, 3, 0, 1) )->setBackgroundColor('mediumaquamarine'); $this->assertEquals('#66cdaaff', $bobj->getArray()['bg_color_obj']->getRgbaHexColor()); } public function testNoColorException() { $this->setExpectedException('\Com\Tecnick\Barcode\Exception'); $this->obj->getBarcodeObj( 'LRAW', '01001100011100001111,10110011100011110000', -2, -2, '', array(-2, 3, 0, 1) ); } public function testExportMethods() { $bobj = $this->obj->getBarcodeObj( 'LRAW,AB,12,E3F', '01001100011100001111,10110011100011110000', -2, -2, 'purple', array(-2, 3, 0, 1) ); $this->assertEquals('01001100011100001111,10110011100011110000', $bobj->getExtendedCode()); $barr = $bobj->getArray(); $this->assertEquals('linear', $barr['type']); $this->assertEquals('LRAW', $barr['format']); $this->assertEquals(array('AB', '12', 'E3F'), $barr['params']); $this->assertEquals('01001100011100001111,10110011100011110000', $barr['code']); $this->assertEquals('01001100011100001111,10110011100011110000', $barr['extcode']); $this->assertEquals(20, $barr['ncols']); $this->assertEquals(2, $barr['nrows']); $this->assertEquals(40, $barr['width']); $this->assertEquals(4, $barr['height']); $this->assertEquals(2, $barr['width_ratio']); $this->assertEquals(2, $barr['height_ratio']); $this->assertEquals(array('T' => 4, 'R' => 3, 'B' => 0, 'L' => 1), $barr['padding']); $this->assertEquals(44, $barr['full_width']); $this->assertEquals(8, $barr['full_height']); $expected = array( array(1,0,1,1), array(4,0,2,1), array(9,0,3,1), array(16,0,4,1), array(0,1,1,1), array(2,1,2,1), array(6,1,3,1), array(12,1,4,1), ); $this->assertEquals($expected, $barr['bars']); $this->assertEquals('#800080ff', $barr['color_obj']->getRgbaHexColor()); $grid = $bobj->getGrid('A', 'B'); $expected = "ABAABBAAABBBAAAABBBB\nBABBAABBBAAABBBBAAAA\n"; $this->assertEquals($expected, $grid); $svg = $bobj->setBackgroundColor('yellow')->getSvgCode(); $expected = ' 01001100011100001111,10110011100011110000 '; $this->assertEquals($expected, $svg); $hdiv = $bobj->setBackgroundColor('lightcoral')->getHtmlDiv(); $expected = '
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
'; $this->assertEquals($expected, $hdiv); if (extension_loaded('imagick')) { $pngik = $bobj->setBackgroundColor('white')->getPngData(true); $this->assertEquals('PNG', substr($pngik, 1, 3)); } $pnggd = $bobj->setBackgroundColor('white')->getPngData(false); $this->assertEquals('PNG', substr($pnggd, 1, 3)); $pnggd = $bobj->setBackgroundColor('')->getPngData(false); $this->assertEquals('PNG', substr($pnggd, 1, 3)); } /** * @runInSeparateProcess */ public function testGetSvg() { $bobj = $this->obj->getBarcodeObj( 'LRAW,AB,12,E3F', '01001100011100001111,10110011100011110000', -2, -2, 'purple' ); ob_start(); $bobj->getSvg(); $svg = ob_get_clean(); $this->assertEquals('86e0362768e8b1b26032381232c0367f', md5($svg)); } /** * @runInSeparateProcess */ public function testGetPng() { $bobj = $this->obj->getBarcodeObj( 'LRAW,AB,12,E3F', '01001100011100001111,10110011100011110000', -2, -2, 'purple' ); ob_start(); $bobj->getPng(); $png = ob_get_clean(); $this->assertEquals('PNG', substr($png, 1, 3)); } }