Add tests for ApiQueryAllInfoboxes (#42)

This commit is contained in:
Universal Omega 2021-12-15 16:19:47 -07:00 committed by GitHub
parent de39a61206
commit a7a41fa0f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 16 deletions

View file

@ -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

View file

@ -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();

View file

@ -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;

View file

@ -0,0 +1,23 @@
<?php
/**
* @group medium
* @coversDefaultClass ApiQueryAllInfoboxes
*/
class QueryAllInfoboxesTest extends ApiTestCase {
/**
* @covers ::__construct
* @covers ::execute
* @covers ::createLabel
* @covers AllInfoboxesQueryPage::doQuery
*/
public function testQueryAllInfoboxes() {
$this->doApiRequest( [
'action' => 'query',
'list' => 'allinfoboxes',
], null, null, self::getTestUser()->getUser() );
$this->addToAssertionCount( 1 );
}
}