Drop tag_summary and valid_tag tables
[lhc/web/wiklou.git] / tests / phpunit / includes / changetags / ChangeTagsTest.php
index 8265af8..f1ee99f 100644 (file)
@@ -13,8 +13,6 @@ class ChangeTagsTest extends MediaWikiTestCase {
 
                $this->tablesUsed[] = 'change_tag';
                $this->tablesUsed[] = 'change_tag_def';
-               $this->tablesUsed[] = 'tag_summary';
-               $this->tablesUsed[] = 'valid_tag';
 
                // Truncate these to avoid the supposed-to-be-unused IDs in tests here turning
                // out to be used, leading ChangeTags::updateTags() to pick up bogus rc_id,
@@ -421,6 +419,102 @@ class ChangeTagsTest extends MediaWikiTestCase {
                $this->assertEquals( $expected2, iterator_to_array( $res2, false ) );
        }
 
+       public function testUpdateTagsSkipDuplicates() {
+               // FIXME: fails under postgres
+               $this->markTestSkippedIfDbType( 'postgres' );
+
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->delete( 'change_tag', '*' );
+               $dbw->delete( 'change_tag_def', '*' );
+
+               $rcId = 123;
+               ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId );
+               ChangeTags::updateTags( [ 'tag2', 'tag3' ], [], $rcId );
+
+               $dbr = wfGetDB( DB_REPLICA );
+
+               $expected = [
+                       (object)[
+                               'ctd_name' => 'tag1',
+                               'ctd_id' => 1,
+                               'ctd_count' => 1
+                       ],
+                       (object)[
+                               'ctd_name' => 'tag2',
+                               'ctd_id' => 2,
+                               'ctd_count' => 1
+                       ],
+                       (object)[
+                               'ctd_name' => 'tag3',
+                               'ctd_id' => 3,
+                               'ctd_count' => 1
+                       ],
+               ];
+               $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' );
+               $this->assertEquals( $expected, iterator_to_array( $res, false ) );
+
+               $expected2 = [
+                       (object)[
+                               'ct_tag_id' => 1,
+                               'ct_rc_id' => 123
+                       ],
+                       (object)[
+                               'ct_tag_id' => 2,
+                               'ct_rc_id' => 123
+                       ],
+                       (object)[
+                               'ct_tag_id' => 3,
+                               'ct_rc_id' => 123
+                       ],
+               ];
+               $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id' ], '' );
+               $this->assertEquals( $expected2, iterator_to_array( $res2, false ) );
+       }
+
+       public function testUpdateTagsDoNothingOnRepeatedCall() {
+               // FIXME: fails under postgres
+               $this->markTestSkippedIfDbType( 'postgres' );
+
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->delete( 'change_tag', '*' );
+               $dbw->delete( 'change_tag_def', '*' );
+
+               $rcId = 123;
+               ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId );
+               $res = ChangeTags::updateTags( [ 'tag2', 'tag1' ], [], $rcId );
+               $this->assertEquals( [ [], [], [ 'tag1', 'tag2' ] ], $res );
+
+               $dbr = wfGetDB( DB_REPLICA );
+
+               $expected = [
+                       (object)[
+                               'ctd_name' => 'tag1',
+                               'ctd_id' => 1,
+                               'ctd_count' => 1
+                       ],
+                       (object)[
+                               'ctd_name' => 'tag2',
+                               'ctd_id' => 2,
+                               'ctd_count' => 1
+                       ],
+               ];
+               $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' );
+               $this->assertEquals( $expected, iterator_to_array( $res, false ) );
+
+               $expected2 = [
+                       (object)[
+                               'ct_tag_id' => 1,
+                               'ct_rc_id' => 123
+                       ],
+                       (object)[
+                               'ct_tag_id' => 2,
+                               'ct_rc_id' => 123
+                       ],
+               ];
+               $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id' ], '' );
+               $this->assertEquals( $expected2, iterator_to_array( $res2, false ) );
+       }
+
        public function testDeleteTags() {
                $dbw = wfGetDB( DB_MASTER );
                $dbw->delete( 'change_tag', '*' );
@@ -473,7 +567,6 @@ class ChangeTagsTest extends MediaWikiTestCase {
                $dbw = wfGetDB( DB_MASTER );
                $dbw->delete( 'change_tag', '*' );
                $dbw->delete( 'change_tag_def', '*' );
-               $dbw->delete( 'valid_tag', '*' );
 
                $rcId = 123;
                ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId );
@@ -494,7 +587,5 @@ class ChangeTagsTest extends MediaWikiTestCase {
                ];
                $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_user_defined' ], '' );
                $this->assertEquals( $expected, iterator_to_array( $res, false ) );
-
-               $this->assertEquals( [], $dbr->selectFieldValues( 'valid_tag', 'vt_tag', '' ) );
        }
 }