1<?php
2
3use jucksearm\barcode\Barcode;
4
5class BarcodeTest extends PHPUnit_Framework_TestCase {
6
7 	private $class;
8 	private $tmpDir;
9
10    function setUp() {
11        $this->class = new Barcode;
12        $this->tmpDir = dirname(dirname(__FILE__)).'/tmp';
13    }
14
15    function testHasTmpDirectory()
16    {
17    	$this->assertTrue(is_dir($this->tmpDir));
18    }
19
20    function testBarcodeFactory() {
21    	$data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode')
22		  ->setType('C128')
23		  ->setFile(null)
24		  ->setScale(null)
25		  ->setHeight(null)
26		  ->setRotate(null)
27		  ->setColor(null)
28		  ->getBarcode()
29		  ->getBarcodeArray();
30
31		$this->assertNotEmpty($data);
32    }
33
34    function testCreateHtmlBarcode() {
35    	$data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode')
36		  ->setType('C128')
37		  ->getBarcodeHtmlData();
38
39		$this->assertNotEmpty($data);
40    }
41
42    function testCreatePngBarcode() {
43    	$data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode')
44		  ->setType('C128')
45		  ->getBarcodePngData();
46
47		$this->assertNotEmpty($data);
48    }
49
50    function testCreatePngBarcodeAndSave() {
51    	$file = 'testPng.png';
52    	$data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode')
53		  ->setType('C128')
54		  ->setFile($file)
55		  ->getBarcodePngData();
56
57		$this->assertTrue(is_file($this->tmpDir.DIRECTORY_SEPARATOR.$file));
58
59		unlink($this->tmpDir.DIRECTORY_SEPARATOR.$file);
60    }
61
62    function testCreateSvgBarcode() {
63    	$data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode')
64		  ->setType('C128')
65		  ->getBarcodeSvgData();
66
67		$this->assertNotEmpty($data);
68    }
69
70    function testCreateSvgBarcodeAndSave() {
71    	$file = 'testSvg.svg';
72    	$data = $this->class->factory()->setCode('https://github.com/jucksearm/php-barcode')
73		  ->setType('C128')
74		  ->setFile($file)
75		  ->getBarcodeSvgData();
76
77		$this->assertTrue(is_file($this->tmpDir.DIRECTORY_SEPARATOR.$file));
78
79		unlink($this->tmpDir.DIRECTORY_SEPARATOR.$file);
80    }
81}