From 71b6a5729dfbeb02dd3d5d7b6847c4281426376e Mon Sep 17 00:00:00 2001 From: Tpt Date: Sat, 30 Nov 2013 10:41:26 +0100 Subject: [PATCH] tests: beginning of tests for DjVu files Change-Id: I453b2b1a1c4999150a570e22170a9c630c2ef265 --- tests/phpunit/data/media/LoremIpsum.djvu | Bin 0 -> 3249 bytes tests/phpunit/includes/media/DjVuTest.php | 118 ++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 tests/phpunit/data/media/LoremIpsum.djvu create mode 100644 tests/phpunit/includes/media/DjVuTest.php diff --git a/tests/phpunit/data/media/LoremIpsum.djvu b/tests/phpunit/data/media/LoremIpsum.djvu new file mode 100644 index 0000000000000000000000000000000000000000..42f47cd08f53afee2bf0de7f49ab7864118e6284 GIT binary patch literal 3249 zcmbW2Wmpqz8-_P&Mu(&{C?PE}atKmmz+fOPCGdib4(Swebb~agBc(;@ZV+jdQW}YY z1Chx--b3Gi-!FeX&++`Zj^jSh`+8Im0tj_I0~i26@ls9O7^bH6?;Y?U96)?^xB~#! z76AalW&nU#1^^)01^~z|@%Vy{=bZXU`KcwgM&S7-CwYEG&dzGc7qKgQ)3NXfBkX$xwi|xnAvVD$W zJV^WwdTv>@_(;}cihz?m9JlR#W49u`pDGekH&erafCoov1|Tua6*n4tCV#||YX}|0QBRQBtEi^Y zl5bW5G$9-p;TGa%R!kNeFO0Vi8F3M529>C>H9u*5bBFL(V~~CRR$$|FE!bnjN6+)47P{!l|ipy#%UdW-(C= zVd)*O;|u7aUd&6;i9A`W7Rlhj>af-l3S@28^+-JF$43)jmz@*x$5Vt}aS~C8$LW56 zH65rBMZub9%%I*}V=8DX&T->dR1Bli#aITCeDPfCJsZA5_VH|JACKRblNy2cSW&*zz;p(FcXNd+ zx}gjhWH)sy=XNo@U+HuXV=; zs-9CkI0um;ceT_6A+q1m8wlv``5)qOTK($v*?UR->8F4PXPc2Wk!3u^j_4U$F|EZ} zJ2=-2>V0Zqo_~UrcT;x1VPU2)hsB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|OKQqsH(>2C*AqHp1qA=}?Q9a{s%hq56U_Y6mY#UL z&A)BANKBtAFe$Iv!O%8qKx1QWML;@=JG^-+)!!`_-92z_h(kks_s3GD?)Pim(QaxX zUn_Ya%pF`VZgv#dQ&kLN7vibgV@Del=8uxm_310;_G>CVeoLX;o?Eybb(=NAO~ay> zoE6A_@yX+l6%~JFMf-0n#0pg^>C!&OCS_^cH%^{;)|6Qo=Fe;+=lMdDr+ysx;-eCo zm6zu6C75z(5VsV~bd2gUW)zcYopQ^;WMzAkVzf;heNnl5^k_9e`+t;IdjpCFZA8=u5^bfmW0 zA9`fdM{G^C@l;qT$uk#)ZHKRU9ZlH_$7>Fx-r?>%pPlYds<2Zn8tF;Vd(5;{inEO*h5l;7JPEw3Nid3%J_IqZTyAH;3*;n6E55!w_I$nW3CTv+eTo(=k zhyARY3?6QOrIZ?SqDIoF_p-0w_A#Osx&W;6j&5m+$$s0f>5U@$W8EA4Wy6(q_s`V& z{9x)5xP;ntGsxgL8++{|MK+H{XboU($}_Vm$!oB=%}1hffQHG(#NQc3BpD`D5_JA$ zk=lAs^MEF&g4%3SOWeT=Y{;s{Ii;b`XhiqD%r;Mb+z#!?7j&C@E)EIfu%K+?5>r_# z{>mu&{=9f{hKO4#|3Vl?Mm0^~yer6>SAeZdayKlC&G9zPd(RG_XfA)E_PH#}cEZzM O@3X;pmvP`hcheckIfToolExists( $wgDjvuRenderer ) || + !$this->checkIfToolExists( $wgDjvuDump ) || + !$this->checkIfToolExists( $wgDjvuToXML ) + ) { + $this->markTestSkipped( 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' ); + } + + //file repo setup + $this->filePath = __DIR__ . '/../../data/media/'; + $backend = new FSFileBackend( array( + 'name' => 'localtesting', + 'wikiId' => wfWikiId(), + 'lockManager' => new NullLockManager( array() ), + 'containerPaths' => array( 'data' => $this->filePath ) + ) ); + $this->repo = new FSRepo( array( + 'name' => 'temp', + 'url' => 'http://localhost/thumbtest', + 'backend' => $backend + ) ); + + $this->handler = new DjVuHandler(); + } + + /** + * Check if a tool exist + * + * @param string $path path to the tool + * @return bool + */ + protected function checkIfToolExists( $path ) { + wfSuppressWarnings(); + $result = file_exists( $path ); + wfRestoreWarnings(); + return $result; + } + + protected function dataFile( $name, $type ) { + return new UnregisteredLocalFile( + false, + $this->repo, + 'mwstore://localtesting/data/' . $name, + $type + ); + } + + public function testGetImageSize() { + $this->assertArrayEquals( + array( 2480, 3508, 'DjVu', 'width="2480" height="3508"' ), + $this->handler->getImageSize( null, $this->filePath . '/LoremIpsum.djvu' ), + 'Test file LoremIpsum.djvu should have a size of 2480 * 3508' + ); + } + + public function testInvalidFile() { + $this->assertFalse( + $this->handler->getMetadata( null, $this->filePath . '/README' ), + 'Getting Metadata for an inexistent file should returns false' + ); + } + + public function testPageCount() { + $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); + $this->assertEquals( + 5, + $this->handler->pageCount( $file ), + 'Test file LoremIpsum.djvu should be detected as containing 5 pages' + ); + } + + public function testGetPageDimensions() { + $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); + $this->assertArrayEquals( + array( 2480, 3508 ), + $this->handler->getPageDimensions( $file, 1 ), + 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508' + ); + } + + public function testGetPageText() { + $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); + $this->assertEquals( + "Lorem ipsum \n1 \n", + (string) $this->handler->getPageText( $file, 1 ), + "Text layer of page 1 of file LoremIpsum.djvu should be 'Lorem ipsum \n1 \n'" + ); + } +} -- 2.20.1