wiki.techinc.nl/tests/phpunit/includes/media/DjVuTest.php
Thiemo Kreuz 8c33a391a0 Fix assertArrayEquals() calls with bogus 3rd parameter
This issue came up in I8a49143, see
https://integration.wikimedia.org/ci/job/mediawiki-quibble-vendor-postgres-php70-docker/2453/console
The third parameter of assertArrayEquals() is called $ordered and is
meant to take the order of elements into account. Providing a string sets
this to true. The SQL query in ChangesListSpecialPageTest seems to behave
a bit random in Postgres and does not always return the elements in the
same order. This is fine. It's just the assertion that was to strict, by
accident.

I found a few more instances of the same issue with a regular expression.
In most cases I intentionally changed it to assertSame() because the order
of elements is actually guaranteed by the code, and needs to be (e.g.
mixing width and height of an image would be fatal).

Change-Id: Ice66cab873a7271d55809a486ce28cf637e43e33
2019-03-14 18:02:08 +01:00

69 lines
1.8 KiB
PHP

<?php
/**
* @group Media
* @covers DjVuHandler
*/
class DjVuTest extends MediaWikiMediaTestCase {
/**
* @var DjVuHandler
*/
protected $handler;
protected function setUp() {
parent::setUp();
// cli tool setup
$djvuSupport = new DjVuSupport();
if ( !$djvuSupport->isEnabled() ) {
$this->markTestSkipped(
'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
}
$this->handler = new DjVuHandler();
}
public function testGetImageSize() {
$this->assertSame(
[ 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->assertEquals(
'a:1:{s:5:"error";s:25:"Error extracting metadata";}',
$this->handler->getMetadata( null, $this->filePath . '/some-nonexistent-file' ),
'Getting metadata for an inexistent file should return 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->assertSame(
[ 'width' => 2480, 'height' => 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'"
);
}
}