Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / InitSiteStatsTest.php
blobf54998c75a68443e6175d338246c91dd77e434fe
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use InitSiteStats;
6 use MediaWiki\MainConfigNames;
7 use MediaWiki\SiteStats\SiteStats;
8 use MediaWiki\Title\Title;
10 /**
11 * @covers \InitSiteStats
12 * @group Database
13 * @author Dreamy Jazz
15 class InitSiteStatsTest extends MaintenanceBaseTestCase {
16 public function getMaintenanceClass() {
17 return InitSiteStats::class;
20 /** @dataProvider provideExecute */
21 public function testExecute( $options, $expectedRow, $expectedOutputString ) {
22 $this->overrideConfigValue( MainConfigNames::ArticleCountMethod, 'any' );
23 // Truncate the site_stats table so that we can check whether it gets populated by the maintenance script
24 $this->truncateTable( 'site_stats' );
25 // Run the maintenance script
26 foreach ( $options as $name => $value ) {
27 $this->maintenance->setOption( $name, $value );
29 $this->maintenance->execute();
30 $this->expectOutputString( $expectedOutputString );
31 $this->newSelectQueryBuilder()
32 ->select( SiteStats::selectFields() )
33 ->from( 'site_stats' )
34 ->caller( __METHOD__ )
35 ->assertRowValue( array_values( $expectedRow ) );
38 public static function provideExecute() {
39 return [
40 'Dry-run' => [
41 [],
43 'ss_total_edits' => 0, 'ss_good_articles' => 0, 'ss_total_pages' => 0,
44 'ss_users' => 0, 'ss_active_users' => 0, 'ss_images' => 0,
46 "Refresh Site Statistics\n\nCounting total edits...3\nCounting number of articles...1\n" .
47 "Counting total pages...2\nCounting number of users...3\nCounting number of images...2\n\n" .
48 "To update the site statistics table, run the script with the --update option.\n\nDone.\n",
50 'Non dry-run' => [
51 [ 'update' => 1 ],
53 'ss_total_edits' => 3, 'ss_good_articles' => 1, 'ss_total_pages' => 2,
54 'ss_users' => 3, 'ss_active_users' => 0, 'ss_images' => 2,
56 "Refresh Site Statistics\n\nCounting total edits...3\nCounting number of articles...1\n" .
57 "Counting total pages...2\nCounting number of users...3\nCounting number of images...2\n\n" .
58 "Updating site statistics...done.\n\nDone.\n",
60 'Non dry-run with also calculating active users number' => [
61 [ 'update' => 1, 'active' => 1 ],
63 'ss_total_edits' => 3, 'ss_good_articles' => 1, 'ss_total_pages' => 2,
64 'ss_users' => 3, 'ss_active_users' => 2, 'ss_images' => 2,
66 "Refresh Site Statistics\n\nCounting total edits...3\nCounting number of articles...1\n" .
67 "Counting total pages...2\nCounting number of users...3\nCounting number of images...2\n\n" .
68 "Updating site statistics...done.\n\nCounting and updating active users...2\n\nDone.\n",
73 public function addDBDataOnce() {
74 $firstTestUser = $this->getMutableTestUser()->getUser();
75 $secondTestUser = $this->getMutableTestUser()->getUser();
76 $thirdTestUser = $this->getMutableTestUser()->getUser();
77 // Create a testing article with two edits
78 $testPage = Title::newFromText( 'Testing1234' );
79 $this->editPage( $testPage, 'testing', '', NS_MAIN, $firstTestUser );
80 $this->editPage( $testPage, 'testingcontent1234', '', NS_MAIN, $secondTestUser );
81 // Create a user page for the first test user
82 $this->editPage( $firstTestUser->getUserPage(), 'testingabc', '', NS_MAIN, $firstTestUser );
83 // Add some testing rows to the image table to simulate images existing.
84 $this->getDb()->newInsertQueryBuilder()
85 ->insertInto( 'image' )
86 ->rows( [
88 'img_name' => 'Random-13m.png',
89 'img_size' => 54321,
90 'img_width' => 1000,
91 'img_height' => 1800,
92 'img_metadata' => '',
93 'img_bits' => 16,
94 'img_media_type' => MEDIATYPE_BITMAP,
95 'img_major_mime' => 'image',
96 'img_minor_mime' => 'png',
97 'img_description_id' => 0,
98 'img_actor' => $firstTestUser->getActorId(),
99 'img_timestamp' => $this->getDb()->timestamp( '20201105234242' ),
100 'img_sha1' => 'sy02psim0bgdh0jt4vdltuzoh7j80yu',
103 'img_name' => 'Random-112m.png',
104 'img_size' => 54321,
105 'img_width' => 1000,
106 'img_height' => 1800,
107 'img_metadata' => '',
108 'img_bits' => 16,
109 'img_media_type' => MEDIATYPE_BITMAP,
110 'img_major_mime' => 'image',
111 'img_minor_mime' => 'png',
112 'img_description_id' => 0,
113 'img_actor' => $firstTestUser->getActorId(),
114 'img_timestamp' => $this->getDb()->timestamp( '20201105235242' ),
115 'img_sha1' => 'sy02psim0bgdh0jt4vdltuzoh7j80ru',
118 ->execute();