From e1d9e951a485354b4962955825e61544360eb6c3 Mon Sep 17 00:00:00 2001 From: smiley Date: Sat, 17 Dec 2016 22:23:58 +0100 Subject: [PATCH] updated tests --- tests/Output/ImageTest.php | 42 +-- tests/Output/MarkupTest.php | 51 +++ tests/Output/OutputTestAbstract.php | 54 ++++ tests/Output/StringTest.php | 51 +-- tests/Output/{string => markup}/str1.html | 0 tests/Output/markup/str1.svg | 124 ++++++++ tests/Output/{string => markup}/str2.html | 0 tests/Output/markup/str2.svg | 366 ++++++++++++++++++++++ tests/Output/{string => markup}/str3.html | 0 tests/Output/{string => markup}/str4.html | 0 10 files changed, 611 insertions(+), 77 deletions(-) create mode 100644 tests/Output/MarkupTest.php create mode 100644 tests/Output/OutputTestAbstract.php rename tests/Output/{string => markup}/str1.html (100%) create mode 100644 tests/Output/markup/str1.svg rename tests/Output/{string => markup}/str2.html (100%) create mode 100644 tests/Output/markup/str2.svg rename tests/Output/{string => markup}/str3.html (100%) rename tests/Output/{string => markup}/str4.html (100%) diff --git a/tests/Output/ImageTest.php b/tests/Output/ImageTest.php index 31c35da0f..2d9fbedb3 100644 --- a/tests/Output/ImageTest.php +++ b/tests/Output/ImageTest.php @@ -15,40 +15,16 @@ use chillerlan\QRCode\Output\QRImage; use chillerlan\QRCode\Output\QRImageOptions; use chillerlan\QRCode\QRCode; -class ImageTest extends \PHPUnit_Framework_TestCase{ +class ImageTest extends OutputTestAbstract{ - /** - * @var \chillerlan\QRCode\Output\QRImageOptions - */ - protected $options; + protected $outputInterfaceClass = QRImage::class; + protected $outputOptionsClass = QRImageOptions::class; - - /** - * @var \chillerlan\QRCode\QRCode - */ - protected $QRCode; - - protected function setUp(){ - $this->options = new QRImageOptions; - } - - public function testOptionsInstance(){ - $this->assertInstanceOf(QRImageOptions::class, $this->options); + public function testOptions(){ $this->assertEquals(QRCode::OUTPUT_IMAGE_PNG, $this->options->type); $this->assertEquals(true, $this->options->base64); } - public function testImageInstance(){ - $this->assertInstanceOf(QRImage::class, new QRImage); - } - - public function testImageInstanceWithOptionsOverride(){ - $this->options->type = 'foobar'; - $this->options->pngCompression = 42; - $this->options->jpegQuality = 'OVER 9000!!!'; - $this->assertInstanceOf(QRImage::class, new QRImage($this->options)); - } - public function imageDataProvider(){ return [ [QRCode::OUTPUT_IMAGE_PNG, 'foobar', 'img1.png.uri'], @@ -65,19 +41,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase{ */ public function testImageOutput($type, $data, $expected){ $this->options->type = $type; - $output = (new QRCode($data, new QRImage($this->options)))->output(); + $output = (new QRCode($data, new $this->outputInterfaceClass($this->options)))->output(); // jpeg test is causing trouble if($type !== QRCode::OUTPUT_IMAGE_JPG){ $this->assertEquals(file_get_contents(__DIR__.'/image/'.$expected), $output); } } - /** - * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException - * @expectedExceptionMessage Invalid matrix! - */ - public function testSetMatrixException(){ - (new QRImage)->setMatrix([]); - } - } diff --git a/tests/Output/MarkupTest.php b/tests/Output/MarkupTest.php new file mode 100644 index 000000000..571ffca95 --- /dev/null +++ b/tests/Output/MarkupTest.php @@ -0,0 +1,51 @@ + + * @copyright 2016 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeTest\Output; + +use chillerlan\QRCode\Output\QRMarkup; +use chillerlan\QRCode\Output\QRMarkupOptions; +use chillerlan\QRCode\QRCode; + +/** + * Class MarkupTest + */ +class MarkupTest extends OutputTestAbstract{ + + protected $outputInterfaceClass = QRMarkup::class; + protected $outputOptionsClass = QRMarkupOptions::class; + + public function testOptions(){ + $this->assertEquals(QRCode::OUTPUT_MARKUP_SVG, $this->options->type); + } + + public function markupDataProvider(){ + return [ + [QRCode::OUTPUT_MARKUP_HTML, true, 'foobar', 'str1.html'], + [QRCode::OUTPUT_MARKUP_HTML, false, 'foobar', 'str2.html'], + [QRCode::OUTPUT_MARKUP_HTML, true, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str3.html'], + [QRCode::OUTPUT_MARKUP_HTML, false, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str4.html'], + [QRCode::OUTPUT_MARKUP_SVG , null, 'foobar', 'str1.svg'], + [QRCode::OUTPUT_MARKUP_SVG , null, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str2.svg'], + ]; + } + + /** + * @dataProvider markupDataProvider + */ + public function testMarkupOutput($type, $omitEndTag, $data, $expected){ + $this->options->type = $type; + $this->options->htmlOmitEndTag = $omitEndTag; + $this->options->cssClass = 'test'; + $this->assertEquals(file_get_contents(__DIR__.'/markup/'.$expected), (new QRCode($data, new $this->outputInterfaceClass($this->options)))->output()); + } + +} diff --git a/tests/Output/OutputTestAbstract.php b/tests/Output/OutputTestAbstract.php new file mode 100644 index 000000000..8b770f86d --- /dev/null +++ b/tests/Output/OutputTestAbstract.php @@ -0,0 +1,54 @@ + + * @copyright 2016 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeTest\Output; + +/** + * Class OutputTestAbstract + */ +abstract class OutputTestAbstract extends \PHPUnit_Framework_TestCase{ + + protected $outputInterfaceClass; + protected $outputOptionsClass; + + protected $options; + protected $outputInterface; + + protected function setUp(){ + $this->options = new $this->outputOptionsClass; + $this->outputInterface = new $this->outputInterfaceClass($this->options); + } + + public function testInstance(){ + $this->assertInstanceOf($this->outputInterfaceClass, $this->outputInterface); + $this->assertInstanceOf($this->outputOptionsClass, $this->options); + } + + /** + * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException + * @expectedExceptionMessage Invalid output type! + */ + public function testOutputTypeException(){ + $this->options->type = 'foo'; + new $this->outputInterfaceClass($this->options); + } + + /** + * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException + * @expectedExceptionMessage Invalid matrix! + */ + public function testSetMatrixException(){ + /** @var \chillerlan\QRCode\Output\QROutputInterface $outputInterface */ + $outputInterface = new $this->outputInterfaceClass; + $outputInterface->setMatrix([]); + } + +} diff --git a/tests/Output/StringTest.php b/tests/Output/StringTest.php index 4420b80ad..bd4d9c8fa 100644 --- a/tests/Output/StringTest.php +++ b/tests/Output/StringTest.php @@ -15,59 +15,30 @@ use chillerlan\QRCode\Output\QRString; use chillerlan\QRCode\Output\QRStringOptions; use chillerlan\QRCode\QRCode; -class StringTest extends \PHPUnit_Framework_TestCase{ +class StringTest extends OutputTestAbstract{ - /** - * @var \chillerlan\QRCode\Output\QRStringOptions - */ - protected $options; + protected $outputInterfaceClass = QRString::class; + protected $outputOptionsClass = QRStringOptions::class; - protected function setUp(){ - $this->options = new QRStringOptions; - } - - public function testOptionsInstance(){ - $this->assertInstanceOf(QRStringOptions::class, $this->options); - $this->assertEquals(QRCode::OUTPUT_STRING_HTML, $this->options->type); + public function testOptions(){ + $this->assertEquals(QRCode::OUTPUT_STRING_JSON, $this->options->type); } public function stringDataProvider(){ return [ - [QRCode::OUTPUT_STRING_HTML, true, 'foobar', 'str1.html'], - [QRCode::OUTPUT_STRING_HTML, false, 'foobar', 'str2.html'], - [QRCode::OUTPUT_STRING_HTML, true, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str3.html'], - [QRCode::OUTPUT_STRING_HTML, false, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str4.html'], - [QRCode::OUTPUT_STRING_JSON, false, 'foobar', 'str1.json'], - [QRCode::OUTPUT_STRING_JSON, false, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str2.json'], - [QRCode::OUTPUT_STRING_TEXT, false, 'foobar', 'str1.txt'], - [QRCode::OUTPUT_STRING_TEXT, false, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str2.txt'], + [QRCode::OUTPUT_STRING_JSON, 'foobar', 'str1.json'], + [QRCode::OUTPUT_STRING_JSON, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str2.json'], + [QRCode::OUTPUT_STRING_TEXT, 'foobar', 'str1.txt'], + [QRCode::OUTPUT_STRING_TEXT, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'str2.txt'], ]; } /** * @dataProvider stringDataProvider */ - public function testStringOutput($type, $omitEndTag, $data, $expected){ + public function testStringOutput($type, $data, $expected){ $this->options->type = $type; - $this->options->htmlOmitEndTag = $omitEndTag; - $this->assertEquals(file_get_contents(__DIR__.'/string/'.$expected), (new QRCode($data, new QRString($this->options)))->output()); - } - - /** - * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException - * @expectedExceptionMessage Invalid string output type! - */ - public function testOutputTypeException(){ - $this->options->type = 'foo'; - new QRString($this->options); - } - - /** - * @expectedException \chillerlan\QRCode\Output\QRCodeOutputException - * @expectedExceptionMessage Invalid matrix! - */ - public function testSetMatrixException(){ - (new QRString)->setMatrix([]); + $this->assertEquals(file_get_contents(__DIR__.'/string/'.$expected), (new QRCode($data, new $this->outputInterfaceClass($this->options)))->output()); } } diff --git a/tests/Output/string/str1.html b/tests/Output/markup/str1.html similarity index 100% rename from tests/Output/string/str1.html rename to tests/Output/markup/str1.html diff --git a/tests/Output/markup/str1.svg b/tests/Output/markup/str1.svg new file mode 100644 index 000000000..cfbef7ff9 --- /dev/null +++ b/tests/Output/markup/str1.svg @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Output/string/str2.html b/tests/Output/markup/str2.html similarity index 100% rename from tests/Output/string/str2.html rename to tests/Output/markup/str2.html diff --git a/tests/Output/markup/str2.svg b/tests/Output/markup/str2.svg new file mode 100644 index 000000000..249099a71 --- /dev/null +++ b/tests/Output/markup/str2.svg @@ -0,0 +1,366 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Output/string/str3.html b/tests/Output/markup/str3.html similarity index 100% rename from tests/Output/string/str3.html rename to tests/Output/markup/str3.html diff --git a/tests/Output/string/str4.html b/tests/Output/markup/str4.html similarity index 100% rename from tests/Output/string/str4.html rename to tests/Output/markup/str4.html