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