Index: trunk/extensions/FlaggedRevs/FRUserCounters.php |
— | — | @@ -115,7 +115,9 @@ |
116 | 116 | $key = $m[0]; |
117 | 117 | $value = isset( $m[1] ) ? $m[1] : null; |
118 | 118 | if ( $key === 'uniqueContentPages' ) { // list |
119 | | - $value = array_map( 'intval', explode( ',', $value ) ); |
| 119 | + $value = ( $value === '' ) |
| 120 | + ? array() // explode() would make array( 0 => '') |
| 121 | + : array_map( 'intval', explode( ',', $value ) ); |
120 | 122 | } else { |
121 | 123 | $value = intval( $value ); |
122 | 124 | } |
Index: trunk/extensions/FlaggedRevs/maintenance/tests/FRUserCountersTest.php |
— | — | @@ -0,0 +1,98 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once 'PHPUnit\Framework\TestCase.php'; |
| 5 | + |
| 6 | +class FRUserCountersTest extends PHPUnit_Framework_TestCase { |
| 7 | + /** |
| 8 | + * Prepares the environment before running a test. |
| 9 | + */ |
| 10 | + protected function setUp() { |
| 11 | + parent::setUp(); |
| 12 | + } |
| 13 | + |
| 14 | + /** |
| 15 | + * Cleans up the environment after running a test. |
| 16 | + */ |
| 17 | + protected function tearDown() { |
| 18 | + parent::tearDown(); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Constructs the test case. |
| 23 | + */ |
| 24 | + public function __construct() {} |
| 25 | + |
| 26 | + public function testGetAndSaveUserParams() { |
| 27 | + $p = FRUserCounters::getUserParams( -1 ); |
| 28 | + $expected = array( |
| 29 | + 'uniqueContentPages' => array(), |
| 30 | + 'totalContentEdits' => 0, |
| 31 | + 'editComments' => 0, |
| 32 | + 'revertedEdits' => 0 |
| 33 | + ); |
| 34 | + $this->assertEquals( $expected, $p, "Initial params" ); |
| 35 | + |
| 36 | + $expected = array( |
| 37 | + 'uniqueContentPages' => array(), |
| 38 | + 'totalContentEdits' => 666, |
| 39 | + 'editComments' => 666, |
| 40 | + 'revertedEdits' => 13 |
| 41 | + ); |
| 42 | + FRUserCounters::saveUserParams( 1, $expected ); |
| 43 | + $ps = FRUserCounters::getUserParams( 1 ); |
| 44 | + $this->assertEquals( $expected, $ps, "Param save and fetch from DB 1" ); |
| 45 | + |
| 46 | + $expected = array( |
| 47 | + 'uniqueContentPages' => array(23,55), |
| 48 | + 'totalContentEdits' => 666, |
| 49 | + 'editComments' => 666, |
| 50 | + 'revertedEdits' => 13 |
| 51 | + ); |
| 52 | + FRUserCounters::saveUserParams( 1, $expected ); |
| 53 | + $ps = FRUserCounters::getUserParams( 1 ); |
| 54 | + $this->assertEquals( $expected, $ps, "Param save and fetch from DB 2" ); |
| 55 | + } |
| 56 | + |
| 57 | + public function testUpdateUserParams() { |
| 58 | + $p = FRUserCounters::getUserParams( -1 ); |
| 59 | + # Assumes (main) IN content namespace |
| 60 | + $title = Title::makeTitleSafe( 0, 'helloworld' ); |
| 61 | + $article = new Article( $title ); |
| 62 | + |
| 63 | + $copyP = $p; |
| 64 | + $changed = FRUserCounters::updateUserParams( $copyP, $article, "Manual edit comment" ); |
| 65 | + $this->assertEquals( $p['editComments']+1, $copyP['editComments'], "Manual summary" ); |
| 66 | + |
| 67 | + $copyP = $p; |
| 68 | + $changed = FRUserCounters::updateUserParams( $copyP, $article, "/* section */" ); |
| 69 | + $this->assertEquals( $p['editComments'], $copyP['editComments'], "Auto summary" ); |
| 70 | + |
| 71 | + $copyP = $p; |
| 72 | + $changed = FRUserCounters::updateUserParams( $copyP, $article, "edit summary" ); |
| 73 | + $this->assertEquals( $p['totalContentEdits']+1, $copyP['totalContentEdits'], |
| 74 | + "Content edit count on content edit" ); |
| 75 | + $expected = $p['uniqueContentPages']; |
| 76 | + $expected[] = 0; |
| 77 | + $this->assertEquals( $expected, $copyP['uniqueContentPages'], |
| 78 | + "Unique content pages on content edit" ); |
| 79 | + |
| 80 | + # Assumes (user) NOT IN content namespace |
| 81 | + $title = Title::makeTitleSafe( NS_USER, 'helloworld' ); |
| 82 | + $article = new Article( $title ); |
| 83 | + |
| 84 | + $copyP = $p; |
| 85 | + $changed = FRUserCounters::updateUserParams( $copyP, $article, "Manual edit comment" ); |
| 86 | + $this->assertEquals( $p['editComments']+1, $copyP['editComments'], "Manual summary" ); |
| 87 | + |
| 88 | + $copyP = $p; |
| 89 | + $changed = FRUserCounters::updateUserParams( $copyP, $article, "/* section */" ); |
| 90 | + $this->assertEquals( $p['editComments'], $copyP['editComments'], "Auto summary" ); |
| 91 | + |
| 92 | + $copyP = $p; |
| 93 | + $changed = FRUserCounters::updateUserParams( $copyP, $article, "edit summary" ); |
| 94 | + $this->assertEquals( $p['totalContentEdits'], $copyP['totalContentEdits'], |
| 95 | + "Content edit count on non-content edit" ); |
| 96 | + $this->assertEquals( $p['uniqueContentPages'], $copyP['uniqueContentPages'], |
| 97 | + "Unique content pages on non-content edit" ); |
| 98 | + } |
| 99 | +} |
Property changes on: trunk/extensions/FlaggedRevs/maintenance/tests/FRUserCountersTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 100 | + native |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -2065,6 +2065,7 @@ |
2066 | 2066 | |
2067 | 2067 | public static function getUnitTests( &$files ) { |
2068 | 2068 | $files[] = dirname( __FILE__ ) . '/maintenance/tests/FRInclusionManagerTest.php'; |
| 2069 | + $files[] = dirname( __FILE__ ) . '/maintenance/tests/FRUserCountersTest.php'; |
2069 | 2070 | return true; |
2070 | 2071 | } |
2071 | 2072 | |