Update API tests to comply with the new backend for change tags
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiUserrightsTest.php
index 0229e76..c8ecda2 100644 (file)
@@ -8,6 +8,15 @@
  * @covers ApiUserrights
  */
 class ApiUserrightsTest extends ApiTestCase {
+
+       protected function setUp() {
+               parent::setUp();
+               $this->tablesUsed = array_merge(
+                       $this->tablesUsed,
+                       [ 'change_tag', 'change_tag_def', 'logging' ]
+               );
+       }
+
        /**
         * Unsets $wgGroupPermissions['bureaucrat']['userrights'], and sets
         * $wgAddGroups['bureaucrat'] and $wgRemoveGroups['bureaucrat'] to the
@@ -183,6 +192,7 @@ class ApiUserrightsTest extends ApiTestCase {
        }
 
        public function testWithTag() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
                ChangeTags::defineTag( 'custom tag' );
 
                $user = $this->getMutableTestUser()->getUser();
@@ -205,6 +215,31 @@ class ApiUserrightsTest extends ApiTestCase {
                );
        }
 
+       public function testWithTagNewBackend() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
+               ChangeTags::defineTag( 'custom tag' );
+
+               $user = $this->getMutableTestUser()->getUser();
+
+               $this->doSuccessfulRightsChange( 'sysop', [ 'tags' => 'custom tag' ], $user );
+
+               $dbr = wfGetDB( DB_REPLICA );
+               $this->assertSame(
+                       'custom tag',
+                       $dbr->selectField(
+                               [ 'change_tag', 'logging', 'change_tag_def' ],
+                               'ctd_name',
+                               [
+                                       'ct_log_id = log_id',
+                                       'log_namespace' => NS_USER,
+                                       'log_title' => strtr( $user->getName(), ' ', '_' )
+                               ],
+                               __METHOD__,
+                               [ 'change_tag_def' => [ 'INNER JOIN', 'ctd_id = ct_tag_id' ] ]
+                       )
+               );
+       }
+
        public function testWithoutTagPermission() {
                global $wgGroupPermissions;