From a7a41fa0f1e5e94e5de1d6ce648b4dfef2cbc6dd Mon Sep 17 00:00:00 2001 From: Universal Omega <54654040+Universal-Omega@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:19:47 -0700 Subject: [PATCH] Add tests for ApiQueryAllInfoboxes (#42) --- .github/workflows/mediawiki-tests.yml | 6 ----- includes/controllers/ApiQueryAllInfoboxes.php | 8 +++++++ includes/querypage/AllInfoboxesQueryPage.php | 20 ++++++++-------- tests/phpunit/QueryAllInfoboxesTest.php | 23 +++++++++++++++++++ 4 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 tests/phpunit/QueryAllInfoboxesTest.php diff --git a/.github/workflows/mediawiki-tests.yml b/.github/workflows/mediawiki-tests.yml index eeef06a..8234036 100644 --- a/.github/workflows/mediawiki-tests.yml +++ b/.github/workflows/mediawiki-tests.yml @@ -267,12 +267,6 @@ jobs: docker load -i /home/runner/docker-images/"${QUIBBLE_DOCKER_IMAGE}" || \ docker pull "${DOCKER_REGISTRY}/${DOCKER_ORG}/${QUIBBLE_DOCKER_IMAGE}:${QUIBBLE_DOCKER_LATEST_TAG}" - - name: Cache MediaWiki installation - uses: actions/cache@v2 - with: - path: /home/runner/src - key: ${{ runner.os }}-${{ env.MEDIAWIKI_VERSION }}-${{ hashFiles('.github/workflows/dependencies') }} - - name: Download MediaWiki and extensions run: | cd /home/runner diff --git a/includes/controllers/ApiQueryAllInfoboxes.php b/includes/controllers/ApiQueryAllInfoboxes.php index f40a8a1..c9ddc39 100644 --- a/includes/controllers/ApiQueryAllInfoboxes.php +++ b/includes/controllers/ApiQueryAllInfoboxes.php @@ -8,6 +8,14 @@ class ApiQueryAllInfoboxes extends ApiQueryBase { public const MCACHE_KEY = 'allinfoboxes-list'; + /** + * @param ApiQuery $query + * @param string $moduleName + */ + public function __construct( ApiQuery $query, $moduleName ) { + parent::__construct( $query, $moduleName, 'api' ); + } + public function execute() { $db = $this->getDB(); $res = $this->getResult(); diff --git a/includes/querypage/AllInfoboxesQueryPage.php b/includes/querypage/AllInfoboxesQueryPage.php index c7157fc..07fd4c5 100644 --- a/includes/querypage/AllInfoboxesQueryPage.php +++ b/includes/querypage/AllInfoboxesQueryPage.php @@ -14,21 +14,21 @@ class AllInfoboxesQueryPage extends PageQueryPage { $query = [ 'tables' => [ 'page', 'page_props' ], 'fields' => [ - 'namespace' => 'page.page_namespace', - 'title' => 'page.page_title', - 'value' => 'page.page_id', - 'infoboxes' => 'page_props.pp_value' + 'namespace' => 'page_namespace', + 'title' => 'page_title', + 'value' => 'page_id', + 'infoboxes' => 'pp_value' ], 'conds' => [ - 'page.page_is_redirect' => 0, - 'page.page_namespace' => NS_TEMPLATE, - 'page_props.pp_value IS NOT NULL', - 'page_props.pp_value != \'\'' + 'page_is_redirect' => 0, + 'page_namespace' => NS_TEMPLATE, + 'pp_value IS NOT NULL', + 'pp_value != \'\'' ], 'join_conds' => [ 'page_props' => [ 'INNER JOIN', - 'page.page_id = page_props.pp_page AND page_props.pp_propname = "infoboxes"' + 'page_id = pp_page AND pp_propname = "infoboxes"' ] ] ]; @@ -37,7 +37,7 @@ class AllInfoboxesQueryPage extends PageQueryPage { $subpagesBlacklist = $this->getConfig()->get( 'AllInfoboxesSubpagesBlacklist' ); foreach ( $subpagesBlacklist as $subpage ) { - $query['conds'][] = 'page.page_title NOT ' . $dbr->buildLike( "/{$subpage}" ); + $query['conds'][] = 'page_title NOT ' . $dbr->buildLike( "/{$subpage}" ); } return $query; diff --git a/tests/phpunit/QueryAllInfoboxesTest.php b/tests/phpunit/QueryAllInfoboxesTest.php new file mode 100644 index 0000000..bfcfb95 --- /dev/null +++ b/tests/phpunit/QueryAllInfoboxesTest.php @@ -0,0 +1,23 @@ +doApiRequest( [ + 'action' => 'query', + 'list' => 'allinfoboxes', + ], null, null, self::getTestUser()->getUser() ); + $this->addToAssertionCount( 1 ); + } + +}