Index: trunk/extensions/PagedTiffHandler/tests/PagedTiffHandlerTest.php |
— | — | @@ -26,16 +26,15 @@ |
27 | 27 | private $image; |
28 | 28 | private $preCheckError; |
29 | 29 | |
30 | | - function setUp() |
| 30 | + function setUp($autoUpload = false) |
31 | 31 | { |
32 | 32 | global $wgTitle; |
33 | 33 | $wgTitle = Title::newFromText("PagedTiffHandler_UnitTest"); |
34 | 34 | |
35 | 35 | $this->handler = new PagedTiffHandler(); |
36 | | - $this->image = wfFindFile(Title::newFromText('Image:Multipage.tiff')); |
37 | | - if (!$this->image) |
| 36 | + if (!file_exists( dirname(__FILE__) . '/testImages')) |
38 | 37 | { |
39 | | - echo "Please upload the image testImages/multipage.tiff into the wiki\n"; |
| 38 | + echo "testImages directory cannot be found.\n"; |
40 | 39 | $this->preCheckError = true; |
41 | 40 | } |
42 | 41 | if (!file_exists(dirname(__FILE__) . '/testImages/caspian.tif')) |
— | — | @@ -48,12 +47,34 @@ |
49 | 48 | echo "testImages/Multipage.tif cannot be found.\n"; |
50 | 49 | $this->preCheckError = true; |
51 | 50 | } |
52 | | - if (!file_exists( dirname(__FILE__) . '/testImages')) |
| 51 | + $multipageTitle = Title::newFromText('Image:Multipage.tiff'); |
| 52 | + $this->image = wfFindFile($multipageTitle); |
| 53 | + if (!$this->image) |
53 | 54 | { |
54 | | - echo "testImages directory cannot be found.\n"; |
55 | | - $this->preCheckError = true; |
| 55 | + if ($autoUpload) |
| 56 | + { |
| 57 | + echo "testImages/multipage.tiff seems not to be present in the wiki. Trying to upload.\n"; |
| 58 | + $this->image = wfLocalFile( $multipageTitle ); |
| 59 | + $archive = $this->image->publish( dirname(__FILE__) . '/testImages/multipage.tiff' ); |
| 60 | + $this->image->recordUpload( $archive->value, "Test file used for PagedTiffHandler unit test", "No license" ); |
| 61 | + if( WikiError::isError( $archive ) || !$archive->isGood() ) |
| 62 | + { |
| 63 | + echo "Something went wrong. Please manually upload testImages/multipage.tiff\n"; |
| 64 | + $this->preCheckError = true; |
| 65 | + } |
| 66 | + else |
| 67 | + { |
| 68 | + echo "Upload was successful.\n"; |
| 69 | + } |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + echo "Please upload the image testImages/multipage.tiff into the wiki\n"; |
| 74 | + $this->preCheckError = true; |
| 75 | + } |
| 76 | + |
56 | 77 | } |
57 | | - |
| 78 | + |
58 | 79 | $this->path = dirname(__FILE__) . '/testImages/multipage.tiff'; |
59 | 80 | } |
60 | 81 | |
— | — | @@ -106,8 +127,8 @@ |
107 | 128 | $this->assertEquals($this->handler->getPageDimensions( $this->image, 5 ), array('width' => 1024, 'height' => 768) ); |
108 | 129 | $this->assertEquals($this->handler->getPageDimensions( $this->image, 6 ), array('width' => 1024, 'height' => 768) ); |
109 | 130 | $this->assertEquals($this->handler->getPageDimensions( $this->image, 7 ), array('width' => 768, 'height' => 1024) ); |
110 | | - // TODO: check this, -1 is also false |
111 | | - $this->assertEquals($this->handler->getPageDimensions( $this->image, 8 ), false ); |
| 131 | + // return dimensions of last page if page number is too high |
| 132 | + $this->assertEquals($this->handler->getPageDimensions( $this->image, 8 ), array('width' => 768, 'height' => 1024) ); |
112 | 133 | // isMultiPage |
113 | 134 | $this->assertTrue($this->handler->isMultiPage($this->image)); |
114 | 135 | |
— | — | @@ -119,9 +140,11 @@ |
120 | 141 | $this->assertTrue($this->handler->isMetadataValid($this->image, $metadata)); |
121 | 142 | // getMetaArray |
122 | 143 | $metaArray = $this->handler->getMetaArray($this->image); |
| 144 | + |
123 | 145 | $this->assertEquals($metaArray['Pages'], 7); |
124 | | - $this->assertEquals($metaArray['pages'][1]['alpha'], 'False'); |
125 | | - $this->assertEquals($metaArray['pages'][2]['alpha'], 'True'); |
| 146 | + //this is also strtolower in PagedTiffHandler::getThumbExtension |
| 147 | + $this->assertEquals(strtolower($metaArray['pages'][1]['alpha']), 'false'); |
| 148 | + $this->assertEquals(strtolower($metaArray['pages'][2]['alpha']), 'true'); |
126 | 149 | $this->assertEquals($metaArray['exif']['Endianess'], 'MSB'); |
127 | 150 | // formatMetadata |
128 | 151 | $formattedMetadata = $this->handler->formatMetadata($this->image) ; |
— | — | @@ -132,6 +155,6 @@ |
133 | 156 | $wgShowExceptionDetails = true; |
134 | 157 | |
135 | 158 | $t = new PagedTiffHandlerTest(); |
136 | | -$t->setUp(); |
| 159 | +$t->setUp(true); |
137 | 160 | $t->runTest(); |
138 | 161 | ?> |
\ No newline at end of file |