| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Context\RequestContext; |
| 4 |
use MediaWiki\Pager\ImageListPager; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
o |
| 10 |
d |
| 11 |
. |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class ImageListPagerTest extends MediaWikiIntegrationTestCase { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public function testFormatValuesThrowException() { |
| 20 |
$services = $this->getServiceContainer(); |
| 21 |
$page = new ImageListPager( |
| 22 |
RequestContext::getMain(), |
| 23 |
$services->getCommentStore(), |
| 24 |
$services->getLinkRenderer(), |
| 25 |
$services->getConnectionProvider(), |
| 26 |
$services->getRepoGroup(), |
| 27 |
$services->getUserNameUtils(), |
| 28 |
$services->getCommentFormatter(), |
| 29 |
$services->getLinkBatchFactory(), |
| 30 |
null, |
| 31 |
'', |
| 32 |
false, |
| 33 |
false |
| 34 |
); |
| 35 |
$this->expectException( UnexpectedValueException::class ); |
| 36 |
$this->expectExceptionMessage( "invalid_field" ); |
| 37 |
$page->formatValue( 'invalid_field', 'invalid_value' ); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function testFormatValues_img_timestamp() { |
| 44 |
$services = $this->getServiceContainer(); |
| 45 |
$this->setUserLang( 'en' ); |
| 46 |
$page = new ImageListPager( |
| 47 |
RequestContext::getMain(), |
| 48 |
$services->getCommentStore(), |
| 49 |
$services->getLinkRenderer(), |
| 50 |
$services->getConnectionProvider(), |
| 51 |
$services->getRepoGroup(), |
| 52 |
$services->getUserNameUtils(), |
| 53 |
$services->getCommentFormatter(), |
| 54 |
$services->getLinkBatchFactory(), |
| 55 |
null, |
| 56 |
'', |
| 57 |
false, |
| 58 |
false |
| 59 |
); |
| 60 |
$this->assertEquals( '12:34, 15 January 2001', $page->formatValue( 'img_timestamp', '20010115123456' ) ); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public function testFormatValues_img_size() { |
| 67 |
$services = $this->getServiceContainer(); |
| 68 |
$this->setUserLang( 'en' ); |
| 69 |
$page = new ImageListPager( |
| 70 |
RequestContext::getMain(), |
| 71 |
$services->getCommentStore(), |
| 72 |
$services->getLinkRenderer(), |
| 73 |
$services->getConnectionProvider(), |
| 74 |
$services->getRepoGroup(), |
| 75 |
$services->getUserNameUtils(), |
| 76 |
$services->getCommentFormatter(), |
| 77 |
$services->getLinkBatchFactory(), |
| 78 |
null, |
| 79 |
'', |
| 80 |
false, |
| 81 |
false |
| 82 |
); |
| 83 |
|
| 84 |
|
| 85 |
$this->assertEquals( '10 bytes', $page->formatValue( 'img_size', '10' ) ); |
| 86 |
$this->assertEquals( '16 bytes', $page->formatValue( 'img_size', '16' ) ); |
| 87 |
|
| 88 |
|
| 89 |
$this->assertEquals( '1,000 bytes', $page->formatValue( 'img_size', '1000' ) ); |
| 90 |
$this->assertEquals( '1,023 bytes', $page->formatValue( 'img_size', '1023' ) ); |
| 91 |
|
| 92 |
|
| 93 |
$this->assertEquals( '1 KB', $page->formatValue( 'img_size', '1100' ) ); |
| 94 |
$this->assertEquals( '2 KB', $page->formatValue( 'img_size', '1600' ) ); |
| 95 |
|
| 96 |
|
| 97 |
$this->assertEquals( '1 MB', $page->formatValue( 'img_size', '1048576' ) ); |
| 98 |
$this->assertEquals( '1.05 MB', $page->formatValue( 'img_size', '1100000' ) ); |
| 99 |
$this->assertEquals( '1.53 MB', $page->formatValue( 'img_size', '1600000' ) ); |
| 100 |
|
| 101 |
$this->assertEquals( '1 GB', $page->formatValue( 'img_size', '1073741824' ) ); |
| 102 |
$this->assertEquals( '1.02 GB', $page->formatValue( 'img_size', '1100000000' ) ); |
| 103 |
$this->assertEquals( '1.49 GB', $page->formatValue( 'img_size', '1600000000' ) ); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public function testFormatValues_count() { |
| 110 |
$services = $this->getServiceContainer(); |
| 111 |
$page = new ImageListPager( |
| 112 |
RequestContext::getMain(), |
| 113 |
$services->getCommentStore(), |
| 114 |
$services->getLinkRenderer(), |
| 115 |
$services->getConnectionProvider(), |
| 116 |
$services->getRepoGroup(), |
| 117 |
$services->getUserNameUtils(), |
| 118 |
$services->getCommentFormatter(), |
| 119 |
$services->getLinkBatchFactory(), |
| 120 |
null, |
| 121 |
'', |
| 122 |
false, |
| 123 |
false |
| 124 |
); |
| 125 |
|
| 126 |
|
| 127 |
$this->assertSame( '1', $page->formatValue( 'count', '0' ) ); |
| 128 |
$this->assertSame( '2', $page->formatValue( 'count', '1' ) ); |
| 129 |
$this->assertSame( '3', $page->formatValue( 'count', '2' ) ); |
| 130 |
} |
| 131 |
} |