use dataProvider for txt blacklist test

This commit is contained in:
Georg Ehrke 2013-09-27 09:59:04 +02:00
parent 9e4fe10329
commit aa8a145ba8

View file

@ -95,9 +95,6 @@ class Preview extends \PHPUnit_Framework_TestCase {
public function testTxtBlacklist() { public function testTxtBlacklist() {
$user = $this->initFS(); $user = $this->initFS();
$x = 32;
$y = 32;
$txt = 'random text file'; $txt = 'random text file';
$ics = file_get_contents(__DIR__ . '/../data/testcal.ics'); $ics = file_get_contents(__DIR__ . '/../data/testcal.ics');
$vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf'); $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf');
@ -106,13 +103,22 @@ class Preview extends \PHPUnit_Framework_TestCase {
$rootView->mkdir('/'.$user); $rootView->mkdir('/'.$user);
$rootView->mkdir('/'.$user.'/files'); $rootView->mkdir('/'.$user.'/files');
$toTest = array('txt', return array(
'ics', array('txt', $txt, $user, $rootView, false),
'vcf'); 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;
foreach($toTest as $test) {
$sample = '/'.$user.'/files/test.'.$test; $sample = '/'.$user.'/files/test.'.$test;
$rootView->file_put_contents($sample, ${$test}); $rootView->file_put_contents($sample, $data);
$preview = new \OC\Preview($user, 'files/', 'test.'.$test, $x, $y); $preview = new \OC\Preview($user, 'files/', 'test.'.$test, $x, $y);
$image = $preview->getPreview(); $image = $preview->getPreview();
$resource = $image->resource(); $resource = $image->resource();
@ -120,14 +126,11 @@ class Preview extends \PHPUnit_Framework_TestCase {
//http://stackoverflow.com/questions/5702953/imagecolorat-and-transparency //http://stackoverflow.com/questions/5702953/imagecolorat-and-transparency
$colorIndex = imagecolorat($resource, 1, 1); $colorIndex = imagecolorat($resource, 1, 1);
$colorInfo = imagecolorsforindex($resource, $colorIndex); $colorInfo = imagecolorsforindex($resource, $colorIndex);
$isTransparent = ($colorInfo['alpha'] === 127); $this->assertEquals(
$expectedResult,
if($test === 'txt') { $colorInfo['alpha'] === 127,
$this->assertEquals($isTransparent, false); 'Failed asserting that only previews for text files are transparent.'
} else { );
$this->assertEquals($isTransparent, true);
}
}
} }
private function initFS() { private function initFS() {