r97035 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97034‎ | r97035 | r97036 >
Date:01:37, 14 September 2011
Author:krinkle
Status:ok
Tags:
Comment:
Renaming SpecialRecentchangesTest file to match conventions
* There should be no two files with the same name
* Test suite files should be named after the main file containing the code being tested followed by "Test"
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/specials/SpecialRecentchanges.php (deleted) (history)
  • /trunk/phase3/tests/phpunit/includes/specials/SpecialRecentchangesTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/specials/SpecialRecentchanges.php
@@ -1,131 +0,0 @@
2 -<?php
3 -/**
4 - * Test class for SpecialRecentchanges class
5 - *
6 - * Copyright © 2011, Ashar Voultoiz
7 - *
8 - * @author Ashar Voultoiz
9 - */
10 -class SpecialRecentchangesTest extends MediaWikiTestCase {
11 -
12 - /**
13 - * @var SpecialRecentChanges
14 - */
15 - protected $rc;
16 -
17 - function setUp() {
18 - }
19 -
20 - /** helper to test SpecialRecentchanges::buildMainQueryConds() */
21 - private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
22 - $context = new RequestContext;
23 - $context->setRequest( new FauxRequest( $requestOptions ) );
24 -
25 - # setup the rc object
26 - $this->rc = new SpecialRecentChanges();
27 - $this->rc->setContext( $context );
28 - $formOptions = $this->rc->setup( null );
29 -
30 - # Filter out rc_timestamp conditions which depends on the test runtime
31 - # This condition is not needed as of march 2, 2011 -- hashar
32 - # @todo FIXME: Find a way to generate the correct rc_timestamp
33 - $queryConditions = array_filter(
34 - $this->rc->buildMainQueryConds( $formOptions ),
35 - 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
36 - );
37 -
38 - $this->assertEquals(
39 - $expected,
40 - $queryConditions,
41 - $message
42 - );
43 - }
44 -
45 - /** return false if condition begin with 'rc_timestamp ' */
46 - private static function filterOutRcTimestampCondition( $var ) {
47 - return (false === strpos( $var, 'rc_timestamp ' ));
48 -
49 - }
50 -
51 - public function testRcNsFilter() {
52 - $this->assertConditions(
53 - array( # expected
54 - 'rc_bot' => 0,
55 - #0 => "rc_timestamp >= '20110223000000'",
56 - 1 => "rc_namespace = '0'",
57 - ),
58 - array(
59 - 'namespace' => NS_MAIN,
60 - ),
61 - "rc conditions with no options (aka default setting)"
62 - );
63 - }
64 -
65 - public function testRcNsFilterInversion() {
66 - $this->assertConditions(
67 - array( # expected
68 - #0 => "rc_timestamp >= '20110223000000'",
69 - 'rc_bot' => 0,
70 - 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
71 - ),
72 - array(
73 - 'namespace' => NS_MAIN,
74 - 'invert' => 1,
75 - ),
76 - "rc conditions with namespace inverted"
77 - );
78 - }
79 -
80 - /**
81 - * @bug 2429
82 - * @dataProvider provideNamespacesAssociations
83 - */
84 - public function testRcNsFilterAssociation( $ns1, $ns2 ) {
85 - $this->assertConditions(
86 - array( # expected
87 - #0 => "rc_timestamp >= '20110223000000'",
88 - 'rc_bot' => 0,
89 - 1 => sprintf( "rc_namespace IN ('%s','%s')", $ns1, $ns2 ),
90 - ),
91 - array(
92 - 'namespace' => $ns1,
93 - 'associated' => 1,
94 - ),
95 - "rc conditions with namespace inverted"
96 - );
97 - }
98 -
99 - /**
100 - * @bug 2429
101 - * @dataProvider provideNamespacesAssociations
102 - */
103 - public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
104 - $this->assertConditions(
105 - array( # expected
106 - #0 => "rc_timestamp >= '20110223000000'",
107 - 'rc_bot' => 0,
108 - 1 => sprintf( "rc_namespace NOT IN ('%s','%s')", $ns1, $ns2 ),
109 - ),
110 - array(
111 - 'namespace' => $ns1,
112 - 'associated' => 1,
113 - 'invert' => 1,
114 - ),
115 - "rc conditions with namespace inverted"
116 - );
117 - }
118 -
119 - /**
120 - * Provides associated namespaces to test recent changes
121 - * namespaces association filtering.
122 - */
123 - public function provideNamespacesAssociations() {
124 - return array( # (NS => Associated_NS)
125 - array( NS_MAIN, NS_TALK),
126 - array( NS_TALK, NS_MAIN),
127 - );
128 - }
129 -
130 -}
131 -
132 -
Index: trunk/phase3/tests/phpunit/includes/specials/SpecialRecentchangesTest.php
@@ -0,0 +1,131 @@
 2+<?php
 3+/**
 4+ * Test class for SpecialRecentchanges class
 5+ *
 6+ * Copyright © 2011, Ashar Voultoiz
 7+ *
 8+ * @author Ashar Voultoiz
 9+ */
 10+class SpecialRecentchangesTest extends MediaWikiTestCase {
 11+
 12+ /**
 13+ * @var SpecialRecentChanges
 14+ */
 15+ protected $rc;
 16+
 17+ function setUp() {
 18+ }
 19+
 20+ /** helper to test SpecialRecentchanges::buildMainQueryConds() */
 21+ private function assertConditions( $expected, $requestOptions = null, $message = '' ) {
 22+ $context = new RequestContext;
 23+ $context->setRequest( new FauxRequest( $requestOptions ) );
 24+
 25+ # setup the rc object
 26+ $this->rc = new SpecialRecentChanges();
 27+ $this->rc->setContext( $context );
 28+ $formOptions = $this->rc->setup( null );
 29+
 30+ # Filter out rc_timestamp conditions which depends on the test runtime
 31+ # This condition is not needed as of march 2, 2011 -- hashar
 32+ # @todo FIXME: Find a way to generate the correct rc_timestamp
 33+ $queryConditions = array_filter(
 34+ $this->rc->buildMainQueryConds( $formOptions ),
 35+ 'SpecialRecentchangesTest::filterOutRcTimestampCondition'
 36+ );
 37+
 38+ $this->assertEquals(
 39+ $expected,
 40+ $queryConditions,
 41+ $message
 42+ );
 43+ }
 44+
 45+ /** return false if condition begin with 'rc_timestamp ' */
 46+ private static function filterOutRcTimestampCondition( $var ) {
 47+ return (false === strpos( $var, 'rc_timestamp ' ));
 48+
 49+ }
 50+
 51+ public function testRcNsFilter() {
 52+ $this->assertConditions(
 53+ array( # expected
 54+ 'rc_bot' => 0,
 55+ #0 => "rc_timestamp >= '20110223000000'",
 56+ 1 => "rc_namespace = '0'",
 57+ ),
 58+ array(
 59+ 'namespace' => NS_MAIN,
 60+ ),
 61+ "rc conditions with no options (aka default setting)"
 62+ );
 63+ }
 64+
 65+ public function testRcNsFilterInversion() {
 66+ $this->assertConditions(
 67+ array( # expected
 68+ #0 => "rc_timestamp >= '20110223000000'",
 69+ 'rc_bot' => 0,
 70+ 1 => sprintf( "rc_namespace != '%s'", NS_MAIN ),
 71+ ),
 72+ array(
 73+ 'namespace' => NS_MAIN,
 74+ 'invert' => 1,
 75+ ),
 76+ "rc conditions with namespace inverted"
 77+ );
 78+ }
 79+
 80+ /**
 81+ * @bug 2429
 82+ * @dataProvider provideNamespacesAssociations
 83+ */
 84+ public function testRcNsFilterAssociation( $ns1, $ns2 ) {
 85+ $this->assertConditions(
 86+ array( # expected
 87+ #0 => "rc_timestamp >= '20110223000000'",
 88+ 'rc_bot' => 0,
 89+ 1 => sprintf( "rc_namespace IN ('%s','%s')", $ns1, $ns2 ),
 90+ ),
 91+ array(
 92+ 'namespace' => $ns1,
 93+ 'associated' => 1,
 94+ ),
 95+ "rc conditions with namespace inverted"
 96+ );
 97+ }
 98+
 99+ /**
 100+ * @bug 2429
 101+ * @dataProvider provideNamespacesAssociations
 102+ */
 103+ public function testRcNsFilterAssociationWithInversion( $ns1, $ns2 ) {
 104+ $this->assertConditions(
 105+ array( # expected
 106+ #0 => "rc_timestamp >= '20110223000000'",
 107+ 'rc_bot' => 0,
 108+ 1 => sprintf( "rc_namespace NOT IN ('%s','%s')", $ns1, $ns2 ),
 109+ ),
 110+ array(
 111+ 'namespace' => $ns1,
 112+ 'associated' => 1,
 113+ 'invert' => 1,
 114+ ),
 115+ "rc conditions with namespace inverted"
 116+ );
 117+ }
 118+
 119+ /**
 120+ * Provides associated namespaces to test recent changes
 121+ * namespaces association filtering.
 122+ */
 123+ public function provideNamespacesAssociations() {
 124+ return array( # (NS => Associated_NS)
 125+ array( NS_MAIN, NS_TALK),
 126+ array( NS_TALK, NS_MAIN),
 127+ );
 128+ }
 129+
 130+}
 131+
 132+
Property changes on: trunk/phase3/tests/phpunit/includes/specials/SpecialRecentchangesTest.php
___________________________________________________________________
Added: svn:eol-style
1133 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r97036Partial revert r97035, followup r96930: make recentchanges tests pass againdemon03:31, 14 September 2011

Status & tagging log