summaryrefslogtreecommitdiffstats
path: root/tests/lib/preview.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2013-09-29 23:20:34 +0200
committerAndreas Fischer <bantu@owncloud.com>2013-09-29 23:20:34 +0200
commit9ba0edcadb9aa55d44bbfc834f9b25c9f21a0c2e (patch)
tree1e2ae16eb8072e81551d7d35da2c9d84c97fb7ef /tests/lib/preview.php
parenta79294771b9404b38218bf55cef481cc7e452d84 (diff)
parentc5bcefe4dbd5a237693b1a7435a7041c7e85abd4 (diff)
downloadnextcloud-server-9ba0edcadb9aa55d44bbfc834f9b25c9f21a0c2e.tar.gz
nextcloud-server-9ba0edcadb9aa55d44bbfc834f9b25c9f21a0c2e.zip
Merge pull request #4966 from owncloud/text_preview_blacklist
add blacklist to txt preview backend * owncloud/text_preview_blacklist: rename variable in testIsTransparent rename testTxtBlacklist to txtBlacklist move fileView object initialization to testIsTransparent use dataProvider for txt blacklist test add test for txt blacklist add test data for cal and contact preview add blacklist to txt preview backend
Diffstat (limited to 'tests/lib/preview.php')
-rw-r--r--tests/lib/preview.php43
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/lib/preview.php b/tests/lib/preview.php
index bebdc12b500..d0cdd2c44fb 100644
--- a/tests/lib/preview.php
+++ b/tests/lib/preview.php
@@ -92,6 +92,47 @@ class Preview extends \PHPUnit_Framework_TestCase {
$this->assertEquals($image->height(), $maxY);
}
+ public function txtBlacklist() {
+ $txt = 'random text file';
+ $ics = file_get_contents(__DIR__ . '/../data/testcal.ics');
+ $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf');
+
+ return array(
+ array('txt', $txt, false),
+ array('ics', $ics, true),
+ array('vcf', $vcf, true),
+ );
+ }
+
+ /**
+ * @dataProvider txtBlacklist
+ */
+ public function testIsTransparent($extension, $data, $expectedResult) {
+ $user = $this->initFS();
+
+ $rootView = new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ $x = 32;
+ $y = 32;
+
+ $sample = '/'.$user.'/files/test.'.$extension;
+ $rootView->file_put_contents($sample, $data);
+ $preview = new \OC\Preview($user, 'files/', 'test.'.$extension, $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() {
if(\OC\Files\Filesystem::getView()){
$user = \OC_User::getUser();
@@ -105,4 +146,4 @@ class Preview extends \PHPUnit_Framework_TestCase {
return $user;
}
-} \ No newline at end of file
+}