Update API tests to comply with the new backend for change tags
authorAmir Sarabadani <ladsgroup@gmail.com>
Tue, 4 Sep 2018 19:50:46 +0000 (21:50 +0200)
committerAmir Sarabadani <ladsgroup@gmail.com>
Tue, 4 Sep 2018 19:50:46 +0000 (21:50 +0200)
Bug: T194162
Change-Id: I35f6e36f988a9483dcb624c39e3f0cc969724fdf

tests/phpunit/includes/api/ApiBlockTest.php
tests/phpunit/includes/api/ApiDeleteTest.php
tests/phpunit/includes/api/ApiEditPageTest.php
tests/phpunit/includes/api/ApiUserrightsTest.php

index 65adedc..9980f3a 100644 (file)
@@ -12,6 +12,10 @@ class ApiBlockTest extends ApiTestCase {
 
        protected function setUp() {
                parent::setUp();
 
        protected function setUp() {
                parent::setUp();
+               $this->tablesUsed = array_merge(
+                       $this->tablesUsed,
+                       [ 'change_tag', 'change_tag_def', 'logging' ]
+               );
 
                $this->mUser = $this->getMutableTestUser()->getUser();
        }
 
                $this->mUser = $this->getMutableTestUser()->getUser();
        }
@@ -120,6 +124,7 @@ class ApiBlockTest extends ApiTestCase {
        }
 
        public function testBlockWithTag() {
        }
 
        public function testBlockWithTag() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
                ChangeTags::defineTag( 'custom tag' );
 
                $this->doBlock( [ 'tags' => 'custom tag' ] );
                ChangeTags::defineTag( 'custom tag' );
 
                $this->doBlock( [ 'tags' => 'custom tag' ] );
@@ -135,6 +140,26 @@ class ApiBlockTest extends ApiTestCase {
                ) );
        }
 
                ) );
        }
 
+       public function testBlockWithTagNewBackend() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
+               ChangeTags::defineTag( 'custom tag' );
+
+               $this->doBlock( [ 'tags' => 'custom tag' ] );
+
+               $dbw = wfGetDB( DB_MASTER );
+               $this->assertSame( 1, (int)$dbw->selectField(
+                       [ 'change_tag', 'logging', 'change_tag_def' ],
+                       'COUNT(*)',
+                       [ 'log_type' => 'block', 'ctd_name' => 'custom tag' ],
+                       __METHOD__,
+                       [],
+                       [
+                               'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ],
+                               'change_tag_def' => [ 'INNER JOIN', 'ctd_id = ct_tag_id' ],
+                       ]
+               ) );
+       }
+
        public function testBlockWithProhibitedTag() {
                $this->setExpectedException( ApiUsageException::class,
                        'You do not have permission to apply change tags along with your changes.' );
        public function testBlockWithProhibitedTag() {
                $this->setExpectedException( ApiUsageException::class,
                        'You do not have permission to apply change tags along with your changes.' );
index 0f2bcc6..f2db1b2 100644 (file)
  * @covers ApiDelete
  */
 class ApiDeleteTest extends ApiTestCase {
  * @covers ApiDelete
  */
 class ApiDeleteTest extends ApiTestCase {
+
+       protected function setUp() {
+               parent::setUp();
+               $this->tablesUsed = array_merge(
+                       $this->tablesUsed,
+                       [ 'change_tag', 'change_tag_def', 'logging' ]
+               );
+       }
+
        public function testDelete() {
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
        public function testDelete() {
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
@@ -65,6 +74,7 @@ class ApiDeleteTest extends ApiTestCase {
        }
 
        public function testDeleteWithTag() {
        }
 
        public function testDeleteWithTag() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
                ChangeTags::defineTag( 'custom tag' );
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
                ChangeTags::defineTag( 'custom tag' );
@@ -93,6 +103,39 @@ class ApiDeleteTest extends ApiTestCase {
                ) );
        }
 
                ) );
        }
 
+       public function testDeleteWithTagNewBackend() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
+               $name = 'Help:' . ucfirst( __FUNCTION__ );
+
+               ChangeTags::defineTag( 'custom tag' );
+
+               $this->editPage( $name, 'Some text' );
+
+               $this->doApiRequestWithToken( [
+                       'action' => 'delete',
+                       'title' => $name,
+                       'tags' => 'custom tag',
+               ] );
+
+               $this->assertFalse( Title::newFromText( $name )->exists() );
+
+               $dbw = wfGetDB( DB_MASTER );
+               $this->assertSame( 'custom tag', $dbw->selectField(
+                       [ 'change_tag', 'logging', 'change_tag_def' ],
+                       'ctd_name',
+                       [
+                               'log_namespace' => NS_HELP,
+                               'log_title' => ucfirst( __FUNCTION__ ),
+                       ],
+                       __METHOD__,
+                       [],
+                       [
+                               'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ],
+                               'change_tag_def' => [ 'INNER JOIN', 'ctd_id = ct_tag_id' ]
+                       ]
+               ) );
+       }
+
        public function testDeleteWithoutTagPermission() {
                $this->setExpectedException( ApiUsageException::class,
                        'You do not have permission to apply change tags along with your changes.' );
        public function testDeleteWithoutTagPermission() {
                $this->setExpectedException( ApiUsageException::class,
                        'You do not have permission to apply change tags along with your changes.' );
index 852812b..847316a 100644 (file)
@@ -33,6 +33,10 @@ class ApiEditPageTest extends ApiTestCase {
                        'testing-nontext' => 'DummyNonTextContentHandler',
                        'testing-serialize-error' => 'DummySerializeErrorContentHandler',
                ] );
                        'testing-nontext' => 'DummyNonTextContentHandler',
                        'testing-serialize-error' => 'DummySerializeErrorContentHandler',
                ] );
+               $this->tablesUsed = array_merge(
+                       $this->tablesUsed,
+                       [ 'change_tag', 'change_tag_def', 'logging' ]
+               );
        }
 
        public function testEdit() {
        }
 
        public function testEdit() {
@@ -1328,6 +1332,7 @@ class ApiEditPageTest extends ApiTestCase {
        }
 
        public function testEditWithTag() {
        }
 
        public function testEditWithTag() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
                ChangeTags::defineTag( 'custom tag' );
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
                ChangeTags::defineTag( 'custom tag' );
@@ -1344,6 +1349,30 @@ class ApiEditPageTest extends ApiTestCase {
                        'change_tag', 'ct_tag', [ 'ct_rev_id' => $revId ], __METHOD__ ) );
        }
 
                        'change_tag', 'ct_tag', [ 'ct_rev_id' => $revId ], __METHOD__ ) );
        }
 
+       public function testEditWithTagNewBackend() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
+               $name = 'Help:' . ucfirst( __FUNCTION__ );
+
+               ChangeTags::defineTag( 'custom tag' );
+
+               $revId = $this->doApiRequestWithToken( [
+                       'action' => 'edit',
+                       'title' => $name,
+                       'text' => 'Some text',
+                       'tags' => 'custom tag',
+               ] )[0]['edit']['newrevid'];
+
+               $dbw = wfGetDB( DB_MASTER );
+               $this->assertSame( 'custom tag', $dbw->selectField(
+                       [ 'change_tag', 'change_tag_def' ],
+                       'ctd_name',
+                       [ 'ct_rev_id' => $revId ],
+                       __METHOD__,
+                       [ 'change_tag_def' => [ 'INNER JOIN', 'ctd_id = ct_tag_id' ] ]
+                       )
+               );
+       }
+
        public function testEditWithoutTagPermission() {
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
        public function testEditWithoutTagPermission() {
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
index 0229e76..c8ecda2 100644 (file)
@@ -8,6 +8,15 @@
  * @covers ApiUserrights
  */
 class ApiUserrightsTest extends ApiTestCase {
  * @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
        /**
         * Unsets $wgGroupPermissions['bureaucrat']['userrights'], and sets
         * $wgAddGroups['bureaucrat'] and $wgRemoveGroups['bureaucrat'] to the
@@ -183,6 +192,7 @@ class ApiUserrightsTest extends ApiTestCase {
        }
 
        public function testWithTag() {
        }
 
        public function testWithTag() {
+               $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
                ChangeTags::defineTag( 'custom tag' );
 
                $user = $this->getMutableTestUser()->getUser();
                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;
 
        public function testWithoutTagPermission() {
                global $wgGroupPermissions;