From 52f1d5856dfaa9186a05d529674c2dbab9cc90b7 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 24 Sep 2013 13:26:51 +0200 Subject: add test data for cal and contact preview --- tests/data/testcal.ics | 13 +++++++++++++ tests/data/testcontact.vcf | 6 ++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/data/testcal.ics create mode 100644 tests/data/testcontact.vcf (limited to 'tests') diff --git a/tests/data/testcal.ics b/tests/data/testcal.ics new file mode 100644 index 00000000000..e05f01ba1c2 --- /dev/null +++ b/tests/data/testcal.ics @@ -0,0 +1,13 @@ +BEGIN:VCALENDAR +PRODID:-//some random cal software//EN +VERSION:2.0 +BEGIN:VEVENT +CREATED:20130102T120000Z +LAST-MODIFIED:20130102T120000Z +DTSTAMP:20130102T120000Z +UID:f106ecdf-c716-43ef-9d94-4e6f19f2fcfb +SUMMARY:a test cal file +DTSTART;VALUE=DATE:20130101 +DTEND;VALUE=DATE:20130102 +END:VEVENT +END:VCALENDAR \ No newline at end of file diff --git a/tests/data/testcontact.vcf b/tests/data/testcontact.vcf new file mode 100644 index 00000000000..2af963d6916 --- /dev/null +++ b/tests/data/testcontact.vcf @@ -0,0 +1,6 @@ +BEGIN:VCARD +VERSION:3.0 +PRODID:-//some random contact software//EN +N:def;abc;;; +FN:abc def +END:VCARD \ No newline at end of file -- cgit v1.2.3 From 9e4fe103291133ea78427af18693d93bd78d2bd0 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 25 Sep 2013 10:20:40 +0200 Subject: add test for txt blacklist --- tests/lib/preview.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests') diff --git a/tests/lib/preview.php b/tests/lib/preview.php index bebdc12b500..c40b2d03ef9 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -92,6 +92,44 @@ class Preview extends \PHPUnit_Framework_TestCase { $this->assertEquals($image->height(), $maxY); } + public function testTxtBlacklist() { + $user = $this->initFS(); + + $x = 32; + $y = 32; + + $txt = 'random text file'; + $ics = file_get_contents(__DIR__ . '/../data/testcal.ics'); + $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf'); + + $rootView = new \OC\Files\View(''); + $rootView->mkdir('/'.$user); + $rootView->mkdir('/'.$user.'/files'); + + $toTest = array('txt', + 'ics', + 'vcf'); + + foreach($toTest as $test) { + $sample = '/'.$user.'/files/test.'.$test; + $rootView->file_put_contents($sample, ${$test}); + $preview = new \OC\Preview($user, 'files/', 'test.'.$test, $x, $y); + $image = $preview->getPreview(); + $resource = $image->resource(); + + //http://stackoverflow.com/questions/5702953/imagecolorat-and-transparency + $colorIndex = imagecolorat($resource, 1, 1); + $colorInfo = imagecolorsforindex($resource, $colorIndex); + $isTransparent = ($colorInfo['alpha'] === 127); + + if($test === 'txt') { + $this->assertEquals($isTransparent, false); + } else { + $this->assertEquals($isTransparent, true); + } + } + } + private function initFS() { if(\OC\Files\Filesystem::getView()){ $user = \OC_User::getUser(); -- cgit v1.2.3 From aa8a145ba8fe5a429698ac9c508704952a454358 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 27 Sep 2013 09:59:04 +0200 Subject: use dataProvider for txt blacklist test --- tests/lib/preview.php | 53 +++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/lib/preview.php b/tests/lib/preview.php index c40b2d03ef9..5dc4a93acc5 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -95,9 +95,6 @@ class Preview extends \PHPUnit_Framework_TestCase { public function testTxtBlacklist() { $user = $this->initFS(); - $x = 32; - $y = 32; - $txt = 'random text file'; $ics = file_get_contents(__DIR__ . '/../data/testcal.ics'); $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf'); @@ -106,28 +103,34 @@ class Preview extends \PHPUnit_Framework_TestCase { $rootView->mkdir('/'.$user); $rootView->mkdir('/'.$user.'/files'); - $toTest = array('txt', - 'ics', - 'vcf'); - - foreach($toTest as $test) { - $sample = '/'.$user.'/files/test.'.$test; - $rootView->file_put_contents($sample, ${$test}); - $preview = new \OC\Preview($user, 'files/', 'test.'.$test, $x, $y); - $image = $preview->getPreview(); - $resource = $image->resource(); - - //http://stackoverflow.com/questions/5702953/imagecolorat-and-transparency - $colorIndex = imagecolorat($resource, 1, 1); - $colorInfo = imagecolorsforindex($resource, $colorIndex); - $isTransparent = ($colorInfo['alpha'] === 127); - - if($test === 'txt') { - $this->assertEquals($isTransparent, false); - } else { - $this->assertEquals($isTransparent, true); - } - } + return array( + array('txt', $txt, $user, $rootView, false), + array('ics', $ics, $user, $rootView, true), + array('vcf', $vcf, $user, $rootView, true), + ); + } + + /** + * @dataProvider testTxtBlacklist + */ + public function testIsTransparent($test, $data, $user, $rootView, $expectedResult) { + $x = 32; + $y = 32; + + $sample = '/'.$user.'/files/test.'.$test; + $rootView->file_put_contents($sample, $data); + $preview = new \OC\Preview($user, 'files/', 'test.'.$test, $x, $y); + $image = $preview->getPreview(); + $resource = $image->resource(); + + //http://stackoverflow.com/questions/5702953/imagecolorat-and-transparency + $colorIndex = imagecolorat($resource, 1, 1); + $colorInfo = imagecolorsforindex($resource, $colorIndex); + $this->assertEquals( + $expectedResult, + $colorInfo['alpha'] === 127, + 'Failed asserting that only previews for text files are transparent.' + ); } private function initFS() { -- cgit v1.2.3 From 1b13101096493c0c8f02826e373af761fd5cfac6 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 27 Sep 2013 11:01:47 +0200 Subject: move fileView object initialization to testIsTransparent --- tests/lib/preview.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/lib/preview.php b/tests/lib/preview.php index 5dc4a93acc5..98659a7e887 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -93,27 +93,27 @@ class Preview extends \PHPUnit_Framework_TestCase { } public function testTxtBlacklist() { - $user = $this->initFS(); - $txt = 'random text file'; $ics = file_get_contents(__DIR__ . '/../data/testcal.ics'); $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf'); - $rootView = new \OC\Files\View(''); - $rootView->mkdir('/'.$user); - $rootView->mkdir('/'.$user.'/files'); - return array( - array('txt', $txt, $user, $rootView, false), - array('ics', $ics, $user, $rootView, true), - array('vcf', $vcf, $user, $rootView, true), + array('txt', $txt, false), + array('ics', $ics, true), + array('vcf', $vcf, true), ); } /** * @dataProvider testTxtBlacklist */ - public function testIsTransparent($test, $data, $user, $rootView, $expectedResult) { + public function testIsTransparent($test, $data, $expectedResult) { + $user = $this->initFS(); + + $rootView = new \OC\Files\View(''); + $rootView->mkdir('/'.$user); + $rootView->mkdir('/'.$user.'/files'); + $x = 32; $y = 32; -- cgit v1.2.3 From 4e9296a484fbec0a4c725f32ef47716f9e1b56bc Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 27 Sep 2013 11:33:37 +0200 Subject: rename testTxtBlacklist to txtBlacklist --- tests/lib/preview.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/lib/preview.php b/tests/lib/preview.php index 98659a7e887..01d8a57fc68 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -92,7 +92,7 @@ class Preview extends \PHPUnit_Framework_TestCase { $this->assertEquals($image->height(), $maxY); } - public function testTxtBlacklist() { + public function txtBlacklist() { $txt = 'random text file'; $ics = file_get_contents(__DIR__ . '/../data/testcal.ics'); $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf'); @@ -105,7 +105,7 @@ class Preview extends \PHPUnit_Framework_TestCase { } /** - * @dataProvider testTxtBlacklist + * @dataProvider txtBlacklist */ public function testIsTransparent($test, $data, $expectedResult) { $user = $this->initFS(); @@ -146,4 +146,4 @@ class Preview extends \PHPUnit_Framework_TestCase { return $user; } -} \ No newline at end of file +} -- cgit v1.2.3 From c5bcefe4dbd5a237693b1a7435a7041c7e85abd4 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 27 Sep 2013 14:55:37 +0200 Subject: rename variable in testIsTransparent --- tests/lib/preview.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/lib/preview.php b/tests/lib/preview.php index 01d8a57fc68..d0cdd2c44fb 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -107,7 +107,7 @@ class Preview extends \PHPUnit_Framework_TestCase { /** * @dataProvider txtBlacklist */ - public function testIsTransparent($test, $data, $expectedResult) { + public function testIsTransparent($extension, $data, $expectedResult) { $user = $this->initFS(); $rootView = new \OC\Files\View(''); @@ -117,9 +117,9 @@ class Preview extends \PHPUnit_Framework_TestCase { $x = 32; $y = 32; - $sample = '/'.$user.'/files/test.'.$test; + $sample = '/'.$user.'/files/test.'.$extension; $rootView->file_put_contents($sample, $data); - $preview = new \OC\Preview($user, 'files/', 'test.'.$test, $x, $y); + $preview = new \OC\Preview($user, 'files/', 'test.'.$extension, $x, $y); $image = $preview->getPreview(); $resource = $image->resource(); -- cgit v1.2.3