Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,40 @@ jobs:
php: '8.1'
experimental: false
coverage: false
search-image: 'docker-registry.wikimedia.org/repos/search-platform/cirrussearch-elasticsearch-image:v7.10.2-12'
- mw: 'REL1_43'
php: '8.2'
experimental: false
coverage: true
search-image: 'docker-registry.wikimedia.org/repos/search-platform/cirrussearch-elasticsearch-image:v7.10.2-12'
- mw: 'REL1_44'
php: '8.3'
experimental: false
coverage: false
search-image: 'docker-registry.wikimedia.org/repos/search-platform/cirrussearch-elasticsearch-image:v7.10.2-12'
- mw: 'REL1_45'
php: '8.4'
experimental: false
coverage: false
search-image: 'docker-registry.wikimedia.org/repos/search-platform/cirrussearch-elasticsearch-image:v7.10.2-12'
- mw: 'master'
php: '8.5'
experimental: true
experimental: false
coverage: false
search-image: 'docker-registry.wikimedia.org/repos/search-platform/cirrussearch-opensearch-image:v1.3.20-12'

runs-on: ubuntu-latest

services:
elasticsearch:
image: docker-registry.wikimedia.org/releng/cirrus-elasticsearch:7.10.2-s0 # Compatibility info at https://www.mediawiki.org/wiki/Extension:CirrusSearch
image: ${{ matrix.search-image }}
ports:
- 9200:9200
- 9300:9300
env:
discovery.type: single-node
ES_JAVA_OPTS: "-Xms512m -Xmx512m -Dlog4j2.formatMsgNoLookups=true"
OPENSEARCH_JAVA_OPTS: "-Xms512m -Xmx512m"

defaults:
run:
Expand All @@ -65,7 +71,7 @@ jobs:
mediawiki
!mediawiki/extensions/
!mediawiki/vendor/
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v3

- name: Cache Composer cache
uses: actions/cache@v4
Expand Down Expand Up @@ -101,11 +107,21 @@ jobs:
php maintenance/runJobs.php

- name: Run PHPUnit
run: php tests/phpunit/phpunit.php -c extensions/WikibaseFacetedSearch/
run: |
if [ -f tests/phpunit/phpunit.php ]; then
php tests/phpunit/phpunit.php -c extensions/WikibaseFacetedSearch/
else
composer phpunit -- extensions/WikibaseFacetedSearch/tests/
fi
if: ${{ ! matrix.coverage }}

- name: Run PHPUnit with code coverage
run: php tests/phpunit/phpunit.php -c extensions/WikibaseFacetedSearch/ --coverage-clover coverage.xml
run: |
if [ -f tests/phpunit/phpunit.php ]; then
php tests/phpunit/phpunit.php -c extensions/WikibaseFacetedSearch/ --coverage-clover coverage.xml
else
composer phpunit -- extensions/WikibaseFacetedSearch/tests/ --coverage-clover coverage.xml
fi
if: ${{ matrix.coverage }}

- name: Upload code coverage
Expand Down Expand Up @@ -145,7 +161,7 @@ jobs:
mediawiki
mediawiki/extensions/
mediawiki/vendor/
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v3

- name: Cache Composer cache
uses: actions/cache@v4
Expand Down Expand Up @@ -214,7 +230,7 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v3

- name: Install MediaWiki
if: steps.cache-mediawiki.outputs.cache-hit != 'true'
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/installMediaWiki.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ mv mediawiki-$MW_BRANCH mediawiki

cd mediawiki

# phpunit.xml.template is excluded from GitHub tarballs via .gitattributes export-ignore.
# Download it directly from the repo if missing.
if [ ! -f phpunit.xml.template ]; then
wget "https://raw.githubusercontent.com/wikimedia/mediawiki/$MW_BRANCH/phpunit.xml.template" -nv -O phpunit.xml.template 2>/dev/null || true
fi

composer install
php maintenance/install.php --dbtype sqlite --dbuser root --dbname mw --dbpath $(pwd) --pass AdminPassword WikiName AdminUser

Expand Down
3 changes: 2 additions & 1 deletion src/Persistence/PageContentFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MediaWiki\Revision\RevisionLookup;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Title\MalformedTitleException;
use MediaWiki\Title\Title;
use MediaWiki\Title\TitleParser;

class PageContentFetcher {
Expand All @@ -20,7 +21,7 @@ public function __construct(

public function getPageContent( string $pageTitle ): ?Content {
try {
$title = $this->titleParser->parseTitle( $pageTitle );
$title = Title::newFromLinkTarget( $this->titleParser->parseTitle( $pageTitle ) );
} catch ( MalformedTitleException ) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/Search/Query/ListFacetQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function buildQuery( FacetConfig $config, PropertyConstraints $constraint
}

return match ( $this->dataTypeLookup->getDataTypeIdForProperty( $config->propertyId ) ) {
'string' => $this->buildStringQuery( $name, $values ),
'string', 'external-id', 'edtf' => $this->buildStringQuery( $name, $values ),
'wikibase-item' => $this->buildStringQuery( $name, $values ),
'quantity' => $this->buildQuantityQuery( $name, $values ),
'time' => $this->buildTimeQuery( $name, $values ),
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/Search/SearchIndexFieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function getFieldTypeForPropertyId( PropertyId $propertyId ): ?string {
private function getFieldTypeForDataTypeId( string $dataTypeId ): ?string {
return match ( $dataTypeId ) {
'quantity' => SearchIndexField::INDEX_TYPE_NUMBER,
'string' => SearchIndexField::INDEX_TYPE_KEYWORD,
'string', 'external-id', 'edtf' => SearchIndexField::INDEX_TYPE_KEYWORD,
'time' => SearchIndexField::INDEX_TYPE_DATETIME,
'wikibase-item' => SearchIndexField::INDEX_TYPE_KEYWORD,
default => null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@

namespace ProfessionalWiki\WikibaseFacetedSearch\Tests\EntryPoints;

use MediaWiki\SpecialPage\SpecialPage;
use MediaWiki\Title\Title;
use ProfessionalWiki\WikibaseFacetedSearch\WikibaseFacetedSearchExtension;
use SpecialPageTestBase;

/**
* @covers \ProfessionalWiki\WikibaseFacetedSearch\EntryPoints\SpecialWikibaseFacetedSearchConfig
*/
class SpecialWikibaseFacetedSearchConfigTest extends SpecialPageTestBase {

protected function newSpecialPage(): SpecialPage {
return $this->getServiceContainer()->getSpecialPageFactory()->getPage( 'WikibaseFacetedSearchConfig' );
}
class SpecialWikibaseFacetedSearchConfigTest extends \MediaWikiIntegrationTestCase {

public function testRedirect(): void {
$specialRules = $this->newSpecialPage();
$specialPage = $this->getServiceContainer()->getSpecialPageFactory()->getPage( 'WikibaseFacetedSearchConfig' );

$specialRules->execute( null );
$specialPage->execute( null );

$this->assertEquals(
Title::newFromText( WikibaseFacetedSearchExtension::CONFIG_PAGE_TITLE, NS_MEDIAWIKI )->getFullURL(),
$specialRules->getOutput()->getRedirect()
$specialPage->getOutput()->getRedirect()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ListFacetQueryBuilderTest extends TestCase {
private const STRING_PROPERTY = 'P200';
private const TIME_PROPERTY = 'P300';
private const ITEM_PROPERTY = 'P400';
private const EXTERNAL_ID_PROPERTY = 'P500';
private const EDTF_PROPERTY = 'P600';

public function testBuildsQueryForStringList(): void {
$query = $this->newFacetQueryBuilder()->buildQuery(
Expand Down Expand Up @@ -55,7 +57,9 @@ private function newDataTypeLookup(): InMemoryDataTypeLookup {
self::QUANTITY_PROPERTY => 'quantity',
self::STRING_PROPERTY => 'string',
self::TIME_PROPERTY => 'time',
self::ITEM_PROPERTY => 'wikibase-item'
self::ITEM_PROPERTY => 'wikibase-item',
self::EXTERNAL_ID_PROPERTY => 'external-id',
self::EDTF_PROPERTY => 'edtf'
];

foreach ( $types as $pId => $type ) {
Expand Down Expand Up @@ -169,6 +173,38 @@ public function testBuildsAnyValueQuery(): void {
);
}

public function testBuildsQueryForExternalIdList(): void {
$query = $this->newFacetQueryBuilder()->buildQuery(
$this->newListFacetConfig( self::EXTERNAL_ID_PROPERTY ),
new PropertyConstraints(
new NumericPropertyId( self::EXTERNAL_ID_PROPERTY ),
orSelectedValues: [ 'ID-001', 'ID-002' ]
)
);

$this->assertIsTermsQueryWithParams(
self::EXTERNAL_ID_PROPERTY,
[ 'ID-001', 'ID-002' ],
$query
);
}

public function testBuildsQueryForEdtfList(): void {
$query = $this->newFacetQueryBuilder()->buildQuery(
$this->newListFacetConfig( self::EDTF_PROPERTY ),
new PropertyConstraints(
new NumericPropertyId( self::EDTF_PROPERTY ),
orSelectedValues: [ '1850', '1920-03-15' ]
)
);

$this->assertIsTermsQueryWithParams(
self::EDTF_PROPERTY,
[ '1850', '1920-03-15' ],
$query
);
}

public function testBuildsNullQueryWhenListIsEmpty(): void {
$query = $this->newFacetQueryBuilder()->buildQuery(
$this->newListFacetConfig( self::STRING_PROPERTY ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ private function newDataTypeLookup(): InMemoryDataTypeLookup {
'P100' => 'quantity',
'P200' => 'string',
'P300' => 'time',
'P400' => 'wikibase-item'
'P400' => 'wikibase-item',
'P500' => 'external-id',
'P600' => 'edtf'
];

foreach ( $types as $pId => $type ) {
Expand Down Expand Up @@ -132,6 +134,42 @@ private function newProperty( string $id, string $dataType ): Property {
return new Property( new NumericPropertyId( $id ), null, $dataType );
}

public function testCreatesKeywordFieldForExternalIdProperty(): void {
$builder = $this->newBuilder(
new Config(
itemTypeProperty: new NumericPropertyId( 'P1' ),
facets: new FacetConfigList(
$this->newFacetConfig( 'Q1', 'P500' )
)
)
);

$fields = $builder->createFieldObjects();

$this->assertEquals(
new AggregatableKeywordIndexField( 'wbfs_P500', SearchIndexField::INDEX_TYPE_KEYWORD, $this->cirrusSearch->getConfig() ),
$fields['wbfs_P500']
);
}

public function testCreatesKeywordFieldForEdtfProperty(): void {
$builder = $this->newBuilder(
new Config(
itemTypeProperty: new NumericPropertyId( 'P1' ),
facets: new FacetConfigList(
$this->newFacetConfig( 'Q1', 'P600' )
)
)
);

$fields = $builder->createFieldObjects();

$this->assertEquals(
new AggregatableKeywordIndexField( 'wbfs_P600', SearchIndexField::INDEX_TYPE_KEYWORD, $this->cirrusSearch->getConfig() ),
$fields['wbfs_P600']
);
}

public function testDoesNotReturnFieldsForMissingProperties(): void {
$builder = $this->newBuilder(
new Config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SitelinkBasedStatementsLookupTest extends WikibaseFacetedSearchIntegration
private SitelinkBasedStatementsLookup $lookup;

protected function setUp(): void {
parent::setUp();

$this->sitelinkStore = new HashSiteLinkStore();
$this->entityLookup = new InMemoryEntityLookup();
$this->lookup = new SitelinkBasedStatementsLookup(
Expand Down
4 changes: 3 additions & 1 deletion tests/phpunit/WikibaseFacetedSearchIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ protected function deleteConfigPage(): void {
*/
$title = Title::newFromText( 'MediaWiki:' . WikibaseFacetedSearchExtension::CONFIG_PAGE_TITLE );

$this->deletePage( new WikiPage( $title ) );
if ( $title->exists() ) {
$this->deletePage( new WikiPage( $title ) );
}
}

protected function getPageHtml( string $pageTitle ): string {
Expand Down
Loading