1<?php 2 3use jucksearm\barcode\Datamatrix; 4 5class DatamatrixTest extends PHPUnit_Framework_TestCase { 6 7 private $class; 8 private $tmpDir; 9 10 function setUp() { 11 $this->class = new Datamatrix; 12 $this->tmpDir = dirname(dirname(__FILE__)).'/tmp'; 13 } 14 15 function testHasTmpDirectory() 16 { 17 $this->assertTrue(is_dir($this->tmpDir)); 18 } 19 20 function testDatamatrixFactory() { 21 $data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode') 22 ->setFile(null) 23 ->setSize(null) 24 ->setMargin(null) 25 ->setColor(null) 26 ->getBarcode() 27 ->getBarcodeArray(); 28 29 $this->assertNotEmpty($data); 30 } 31 32 function testCreateHtmlDatamatrix() { 33 $data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode') 34 ->getDatamatrixHtmlData(); 35 36 $this->assertNotEmpty($data); 37 } 38 39 function testCreatePngDatamatrix() { 40 $data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode') 41 ->getDatamatrixPngData(); 42 43 $this->assertNotEmpty($data); 44 } 45 46 function testCreatePngDatamatrixAndSave() { 47 $file = 'testPng.png'; 48 $data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode') 49 ->setFile($file) 50 ->getDatamatrixPngData(); 51 52 $this->assertTrue(is_file($this->tmpDir.DIRECTORY_SEPARATOR.$file)); 53 54 unlink($this->tmpDir.DIRECTORY_SEPARATOR.$file); 55 } 56 57 function testCreateSvgDatamatrix() { 58 $data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode') 59 ->getDatamatrixSvgData(); 60 61 $this->assertNotEmpty($data); 62 } 63 64 function testCreateSvgDatamatrixAndSave() { 65 $file = 'testSvg.svg'; 66 $data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode') 67 ->setFile($file) 68 ->getDatamatrixSvgData(); 69 70 $this->assertTrue(is_file($this->tmpDir.DIRECTORY_SEPARATOR.$file)); 71 72 unlink($this->tmpDir.DIRECTORY_SEPARATOR.$file); 73 } 74}