Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/93611


Change subject: Add tests for EnhancedChangesList class
......................................................................

Add tests for EnhancedChangesList class

Change-Id: Ia6a371dda71b11d2b65fd5d117b74dddde92a43c
---
A tests/phpunit/data/changes/enhancedchanges.html
A tests/phpunit/data/changes/enhancedchangesend.html
A tests/phpunit/includes/changes/EnhancedChangesListTest.php
3 files changed, 234 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/11/93611/1

diff --git a/tests/phpunit/data/changes/enhancedchanges.html 
b/tests/phpunit/data/changes/enhancedchanges.html
new file mode 100644
index 0000000..0910c3a
--- /dev/null
+++ b/tests/phpunit/data/changes/enhancedchanges.html
@@ -0,0 +1,5 @@
+<div><table class="mw-collapsible mw-collapsed mw-enhanced-rc 
mw-changeslist-ns0-Xyz mw-changeslist-line-not-watched"><tr><td><span 
class="mw-collapsible-toggle mw-collapsible-arrow mw-enhancedchanges-arrow 
mw-enhancedchanges-arrow-space"></span></td><td 
class="mw-enhanced-rc">&#160;&#160;&#160;&#160;&#160;21:15&#160;</td><td> <span 
class="mw-title"><a href="/wiki/Xyz" title="Xyz" 
class="mw-changeslist-title">Xyz</a></span>‎‎ (<a 
href="/index.php?title=Xyz&amp;curid=5&amp;diff=193&amp;oldid=190" 
title="Xyz">2 changes</a> | history) <span class="mw-changeslist-separator">. 
.</span>  <span dir="ltr" class="mw-plusminus-neg" title="210 bytes after 
change">(-2)</span>‎ <span class="mw-changeslist-separator">. .</span>  <span 
class="changedby">[<a 
href="/index.php?title=User:Mary&amp;action=edit&amp;redlink=1" class="new 
mw-userlink" title="User:Mary (page does not exist)">Mary</a>‎; <a 
href="/wiki/Special:Contributions/127.0.0.2" 
title="Special:Contributions/127.0.0.2" 
class="mw-userlink">127.0.0.2</a>‎]</span><tr><td></td><td 
class="mw-enhanced-rc">&#160;&#160;&#160;&#160;&#160;</td><td 
class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time"><a 
href="/index.php?title=Xyz&amp;curid=5&amp;oldid=193" 
title="Xyz">21:15</a></span> (<a 
href="/index.php?title=Xyz&amp;curid=5&amp;diff=0&amp;oldid=193" 
tabindex="0">cur</a> | <a 
href="/index.php?title=Xyz&amp;curid=5&amp;diff=193&amp;oldid=191" 
title="Xyz">prev</a>) <span class="mw-changeslist-separator">. .</span> <span 
dir="ltr" class="mw-plusminus-pos" title="210 bytes after change">(+3)</span>‎ 
<span class="mw-changeslist-separator">. .</span> <a 
href="/index.php?title=User:Mary&amp;action=edit&amp;redlink=1" class="new 
mw-userlink" title="User:Mary (page does not exist)">Mary</a> <span 
class="mw-usertoollinks">(<a 
href="/index.php?title=User_talk:Mary&amp;action=edit&amp;redlink=1" 
class="new" title="User talk:Mary (page does not exist)">Talk</a> | <a 
href="/wiki/Special:Contributions/Mary" 
title="Special:Contributions/Mary">contribs</a>)</span></td></tr>
+<tr><td></td><td class="mw-enhanced-rc">&#160;&#160;&#160;&#160;&#160;</td><td 
class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time"><a 
href="/index.php?title=Xyz&amp;curid=5&amp;oldid=191" 
title="Xyz">21:21</a></span> (<a 
href="/index.php?title=Xyz&amp;curid=5&amp;diff=0&amp;oldid=191" 
tabindex="2">cur</a> | <a 
href="/index.php?title=Xyz&amp;curid=5&amp;diff=191&amp;oldid=190" 
title="Xyz">prev</a>) <span class="mw-changeslist-separator">. .</span> <span 
dir="ltr" class="mw-plusminus-neg" title="188 bytes after change">(-24)</span>‎ 
<span class="mw-changeslist-separator">. .</span> <a 
href="/wiki/Special:Contributions/127.0.0.2" 
title="Special:Contributions/127.0.0.2" class="mw-userlink">127.0.0.2</a> <span 
class="mw-usertoollinks">(<a 
href="/index.php?title=User_talk:127.0.0.2&amp;action=edit&amp;redlink=1" 
class="new" title="User talk:127.0.0.2 (page does not 
exist)">Talk</a>)</span></td></tr>
+</table>
+<table class="mw-enhanced-rc mw-changeslist-ns0-Abc 
mw-changeslist-line-not-watched"><tr><td class="mw-enhanced-rc"><span 
class="mw-enhancedchanges-arrow-space"></span>&#160;&#160;&#160;&#160;&#160;21:16&#160;</td><td>
 <span class="mw-title"><a href="/wiki/Abc" title="Abc" 
class="mw-changeslist-title">Abc</a></span>‎ (<a 
href="/index.php?title=Abc&amp;curid=35&amp;diff=192&amp;oldid=169" 
tabindex="1">diff</a> | <a 
href="/index.php?title=Abc&amp;curid=35&amp;action=history" 
title="Abc">hist</a>) <span class="mw-changeslist-separator">. .</span> <span 
dir="ltr" class="mw-plusminus-pos" title="212 bytes after change">(+2)</span>‎ 
<span class="mw-changeslist-separator">. .</span>  <a 
href="/index.php?title=User:Mary&amp;action=edit&amp;redlink=1" class="new 
mw-userlink" title="User:Mary (page does not exist)">Mary</a> <span 
class="mw-usertoollinks">(<a 
href="/index.php?title=User_talk:Mary&amp;action=edit&amp;redlink=1" 
class="new" title="User talk:Mary (page does not exist)">Talk</a> | <a 
href="/wiki/Special:Contributions/Mary" 
title="Special:Contributions/Mary">contribs</a>)</span></td></tr></table>
+</div><h4>31 October 2013</h4>
diff --git a/tests/phpunit/data/changes/enhancedchangesend.html 
b/tests/phpunit/data/changes/enhancedchangesend.html
new file mode 100644
index 0000000..f3ed76e
--- /dev/null
+++ b/tests/phpunit/data/changes/enhancedchangesend.html
@@ -0,0 +1,2 @@
+<div><table class="mw-enhanced-rc mw-changeslist-ns0-Xyz 
mw-changeslist-line-not-watched"><tr><td class="mw-enhanced-rc"><span 
class="mw-enhancedchanges-arrow-space"></span>&#160;&#160;&#160;&#160;&#160;21:23&#160;</td><td>
 <span class="mw-title"><a href="/wiki/Xyz" title="Xyz" 
class="mw-changeslist-title">Xyz</a></span>‎ (<a 
href="/index.php?title=Xyz&amp;curid=5&amp;diff=190&amp;oldid=189" 
tabindex="3">diff</a> | <a 
href="/index.php?title=Xyz&amp;curid=5&amp;action=history" 
title="Xyz">hist</a>) <span class="mw-changeslist-separator">. .</span> <span 
dir="ltr" class="mw-plusminus-pos" title="3 bytes after change">(+1)</span>‎ 
<span class="mw-changeslist-separator">. .</span>  <a 
href="/index.php?title=User:Mary&amp;action=edit&amp;redlink=1" class="new 
mw-userlink" title="User:Mary (page does not exist)">Mary</a> <span 
class="mw-usertoollinks">(<a 
href="/index.php?title=User_talk:Mary&amp;action=edit&amp;redlink=1" 
class="new" title="User talk:Mary (page does not exist)">Talk</a> | <a 
href="/wiki/Special:Contributions/Mary" 
title="Special:Contributions/Mary">contribs</a>)</span></td></tr></table>
+</div>
diff --git a/tests/phpunit/includes/changes/EnhancedChangesListTest.php 
b/tests/phpunit/includes/changes/EnhancedChangesListTest.php
new file mode 100644
index 0000000..2b99282
--- /dev/null
+++ b/tests/phpunit/includes/changes/EnhancedChangesListTest.php
@@ -0,0 +1,227 @@
+<?php
+
+/**
+ * @covers EnhancedChangesList
+ *
+ * @todo test more combinations of changes, options, etc.
+ *
+ * @group Database
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ */
+class EnhancedChangesListTest extends MediaWikiTestCase {
+
+       protected $context;
+
+       protected $user;
+
+       public function setUp() {
+               parent::setUp();
+
+               $flags = array(
+                       'newpage' => array( 'letter' => 'newpageletter',
+                               'title' => 'recentchanges-label-newpage' ),
+                       'minor' => array( 'letter' => 'minoreditletter',
+                               'title' => 'recentchanges-label-minor', 'class' 
=> 'minoredit' ),
+                       'bot' => array( 'letter' => 'boteditletter',
+                               'title' => 'recentchanges-label-bot', 'class' 
=> 'botedit' ),
+                       'unpatrolled' => array( 'letter' => 'unpatrolledletter',
+                               'title' => 'recentchanges-label-unpatrolled' )
+               );
+
+               $this->setMwGlobals( array(
+                       'wgLanguageCode' => 'en',
+                       'wgScriptPath' => '',
+                       'wgScript' => '/index.php',
+                       'wgArticlePath' => '/wiki/$1',
+                       'wgRecentChangesFlags' => $flags
+               ) );
+
+               $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
+
+               $this->context = new RequestContext();
+               $this->context->setTitle( $title );
+
+               $this->user = User::newFromName( 'Mary' );
+
+               if ( $this->user->getId() === 0 ) {
+                       $this->user->addToDatabase();
+               }
+
+               $user2 = User::newFromId( 0 );
+               $this->context->setUser( $user2 );
+       }
+
+       public function testBeginRecentChangesList() {
+               $changesList = new EnhancedChangesList( $this->context );
+               $this->assertTrue( $changesList instanceof EnhancedChangesList 
);
+
+               $changesList->beginRecentChangesList();
+
+               $out = $changesList->getContext()->getOutput();
+
+               $expectedStyles = array(
+                       'mediawiki.special.changeslist',
+                       'mediawiki.special.changeslist.enhanced',
+               );
+
+               $this->assertEquals( $expectedStyles, $out->getModuleStyles() );
+
+               $expectedModules = array(
+                       'jquery.makeCollapsible',
+                       'mediawiki.icon'
+               );
+
+               $this->assertEquals( $expectedModules, $out->getModules() );
+       }
+
+       /**
+        * @dataProvider recentChangesLineProvider
+        */
+       public function testRecentChangesLine( $expected ) {
+               $changesList = new EnhancedChangesList( $this->context );
+               $changesList->beginRecentChangesList();
+               $changes = $this->getRecentChanges();
+
+               $line = $changesList->recentChangesLine( $changes[0], false );
+               $this->assertEquals( $expected[0], $line );
+
+               $line = $changesList->recentChangesLine( $changes[1], false );
+               $this->assertEquals( $expected[1], $line );
+
+               $line = $changesList->recentChangesLine( $changes[2], false );
+               $this->assertEquals( $expected[2], $line );
+
+               $line = $changesList->recentChangesLine( $changes[3], false );
+               $this->assertEquals( $expected[3], $line );
+       }
+
+       public function recentChangesLineProvider() {
+               $expected1 = "<h4>3 November 2013</h4>\n";
+               $expected4 = file_get_contents( __DIR__ . 
'/../../data/changes/enhancedchanges.html' );
+
+               return array(
+                       array(
+                               array( $expected1, '', '', $expected4 )
+                       )
+               );
+       }
+
+       /**
+        * @dataProvider endRecentChangesListProvider
+        */
+       public function testEndRecentChangesList( $expected ) {
+               $changesList = new EnhancedChangesList( $this->context );
+               $changesList->beginRecentChangesList();
+               $changes = $this->getRecentChanges();
+
+               foreach( $changes as $change ) {
+                       $changesList->recentChangesLine( $change, false );
+               }
+
+               $end = $changesList->endRecentChangesList();
+               $this->assertEquals( $expected, $end );
+       }
+
+       public function endRecentChangesListProvider() {
+               return array(
+                       array( trim( file_get_contents( __DIR__ . 
'/../../data/changes/enhancedchangesend.html' ) ) )
+               );
+       }
+
+       protected function getRecentChanges() {
+               $base = array(
+                       'rc_user' => $this->user->getId(),
+                       'rc_user_text' => $this->user->getName(),
+                       'rc_namespace' => 0,
+                       'rc_title' => 'Xyz',
+                       'rc_comment' => '',
+                       'rc_minor' => 0,
+                       'rc_bot' => 0,
+                       'rc_cur_id' => 5,
+                       'rc_type' => 0,
+                       'rc_patrolled' => 1,
+                       'rc_ip' => '127.0.0.1',
+                       'rc_deleted' => 0,
+                       'rc_logid' => 0,
+                       'rc_log_type' => null,
+                       'rc_log_action' => '',
+                       'rc_params' => '',
+                       'rc_source' => 'mw.edit'
+               );
+
+               $rows = array();
+               $rows[] = array_merge(
+                       $base,
+                       array(
+                               'rc_id' => 547,
+                               'rc_timestamp' => '20131103211549',
+                               'rc_cur_time' => '20131103211549',
+                               'rc_this_oldid' => 193,
+                               'rc_last_oldid' => 191,
+                               'rc_old_len' => 207,
+                               'rc_new_len' => 210,
+                       )
+               );
+
+               $rows[] = array_merge(
+                       $base,
+                       array(
+                               'rc_id' => 546,
+                               'rc_timestamp' => '20131103211649',
+                               'rc_cur_time' => '20131103211649',
+                               'rc_title' => 'Abc',
+                               'rc_cur_id' => 35,
+                               'rc_this_oldid' => 192,
+                               'rc_last_oldid' => 169,
+                               'rc_old_len' => 210,
+                               'rc_new_len' => 212,
+                       )
+               );
+
+               $rows[] = array_merge(
+                       $base,
+                       array(
+                               'rc_id' => 545,
+                               'rc_timestamp' => '20131103212153',
+                               'rc_cur_time' => '20131103212153',
+                               'rc_user' => 0,
+                               'rc_user_text' => '127.0.0.2',
+                               'rc_this_oldid' => 191,
+                               'rc_last_oldid' => 190,
+                               'rc_ip' => '127.0.0.2',
+                               'rc_old_len' => 212,
+                               'rc_new_len' => 188,
+                       )
+               );
+
+               $rows[] = array_merge(
+                       $base,
+                       array(
+                               'rc_id' => 544,
+                               'rc_timestamp' => '20131031212339',
+                               'rc_cur_time' => '20131031212339',
+                               'rc_this_oldid' => 190,
+                               'rc_last_oldid' => 189,
+                               'rc_old_len' => 2,
+                               'rc_new_len' => 3,
+                       )
+               );
+
+               $changes = array();
+               $counter = 0;
+
+               foreach( $rows as $row ) {
+                       $change = new RecentChange();
+                       $change->setAttribs( $row );
+                       $change->counter = $counter;
+                       $changes[] = $change;
+
+                       $counter++;
+               }
+
+               return $changes;
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/93611
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6a371dda71b11d2b65fd5d117b74dddde92a43c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to