3 use MediaWiki\Context\RequestContext
;
4 use MediaWiki\Pager\ImageListPager
;
7 * Test class for ImageListPagerTest class.
9 * Copyright © 2013, Antoine Musso
10 * Copyright © 2013, Siebrand Mazeland
11 * Copyright © 2013, Wikimedia Foundation Inc.
15 class ImageListPagerTest
extends MediaWikiIntegrationTestCase
{
17 * @covers \MediaWiki\Pager\ImageListPager::formatValue
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(),
35 $this->expectException( UnexpectedValueException
::class );
36 $this->expectExceptionMessage( "invalid_field" );
37 $page->formatValue( 'invalid_field', 'invalid_value' );
41 * @covers \MediaWiki\Pager\ImageListPager::formatValue
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(),
60 $this->assertEquals( '12:34, 15 January 2001', $page->formatValue( 'img_timestamp', '20010115123456' ) );
64 * @covers \MediaWiki\Pager\ImageListPager::formatValue
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(),
84 // For very small values we specify exactly
85 $this->assertEquals( '10 bytes', $page->formatValue( 'img_size', '10' ) );
86 $this->assertEquals( '16 bytes', $page->formatValue( 'img_size', '16' ) );
88 // Above 999 but below 1024 we report bytes with thousands separator
89 $this->assertEquals( '1,000 bytes', $page->formatValue( 'img_size', '1000' ) );
90 $this->assertEquals( '1,023 bytes', $page->formatValue( 'img_size', '1023' ) );
92 // For kilobytes we round to the nearest
93 $this->assertEquals( '1 KB', $page->formatValue( 'img_size', '1100' ) );
94 $this->assertEquals( '2 KB', $page->formatValue( 'img_size', '1600' ) );
96 // For megabytes and above we specify up to 2 decimal places if appropriate
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' ) );
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' ) );
107 * @covers \MediaWiki\Pager\ImageListPager::formatValue
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(),
126 // Values are 0-indexed but humans count from 1.
127 $this->assertSame( '1', $page->formatValue( 'count', '0' ) );
128 $this->assertSame( '2', $page->formatValue( 'count', '1' ) );
129 $this->assertSame( '3', $page->formatValue( 'count', '2' ) );