diff options
author | Georg Ehrke <developer@georgehrke.com> | 2013-09-27 09:59:04 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2013-09-27 09:59:04 +0200 |
commit | aa8a145ba8fe5a429698ac9c508704952a454358 (patch) | |
tree | 150d0eabb3739510e083047508366cbab672e3fc /tests | |
parent | 9e4fe103291133ea78427af18693d93bd78d2bd0 (diff) | |
download | nextcloud-server-aa8a145ba8fe5a429698ac9c508704952a454358.tar.gz nextcloud-server-aa8a145ba8fe5a429698ac9c508704952a454358.zip |
use dataProvider for txt blacklist test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/preview.php | 53 |
1 files changed, 28 insertions, 25 deletions
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() { |