This repository has been archived by the owner on Jun 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
133 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace MediaWiki\Extension\FacetedCategory\Tests\Integration\Hooks; | ||
|
||
use CommentStoreComment; | ||
use MediaWikiIntegrationTestCase; | ||
use Title; | ||
use WikitextContent; | ||
|
||
/** | ||
* @group Database | ||
* @covers MediaWiki\Extension\FacetedCategory\Hooks\RecursiveCategory | ||
*/ | ||
class RecursiveCategoryTest extends MediaWikiIntegrationTestCase { | ||
protected function assertCategory( $title, $expected, string $message = '' ) { | ||
$actual = $this->db->selectFieldValues( | ||
'categorylinks', | ||
'cl_to', | ||
[ | ||
'cl_from' => $title->getId(), | ||
], | ||
); | ||
$this->assertEqualsCanonicalizing( $expected, $actual, $message ); | ||
} | ||
|
||
public function testCategorizedUsingParent() { | ||
$parent = $this->createTitle( 'Category:Facet/Parent1', '[[Category:Facet/Cat1]][[Category:Facet/Cat2]]' ); | ||
$child = $this->createTitle( 'Child1', '[[Category:Facet/Parent1]]' ); | ||
$this->assertCategory( $child, [ | ||
'Facet/Cat1', | ||
'Facet/Cat2', | ||
'Facet/Parent1', | ||
], | ||
'Should be registered to the specified category including the grandparent categories.' | ||
); | ||
} | ||
|
||
public function testLateAddingCategoryToParent() { | ||
$parentText = 'Facet/Parent-' . mt_rand(); | ||
$child = $this->createTitle( 'Child-' . mt_rand(), "[[Category:$parentText]]" ); | ||
$parent = $this->createTitle( "Category:$parentText", '[[Category:Facet/Cat1]]' ); | ||
$this->assertCategory( $child, [ $parentText ] ); | ||
|
||
$this->runJobs(); | ||
|
||
$this->assertCategory( $child, [ | ||
'Facet/Cat1', | ||
$parentText, | ||
], | ||
'Should be registered to the specified category including the grandparent categories' | ||
); | ||
} | ||
|
||
public function testGrandParentCategoryChange() { | ||
$suffix = mt_rand(); | ||
$child = $this->createTitle( "Child-$suffix", "[[Category:Facet/Parent-$suffix]]" ); | ||
$parent = $this->createTitle( "Category:Facet/Parent-$suffix", "[[Category:Facet/GrandParent-$suffix]]" ); | ||
$grandParent = $this->createTitle( "Category:Facet/GrandParent-$suffix", "[[Category:Facet/Cat1-$suffix]]" ); | ||
|
||
$this->runJobs(); | ||
|
||
$this->assertCategory( $child, [ | ||
"Facet/Cat1-$suffix", | ||
"Facet/Parent-$suffix", | ||
"Facet/GrandParent-$suffix", | ||
] ); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param string $content | ||
* @return Title | ||
*/ | ||
protected function createTitle( $name, $content ) { | ||
$content = new WikitextContent( $content ); | ||
|
||
$title = Title::newFromText( $name ); | ||
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); | ||
|
||
$updater = $page->newPageUpdater( $this->getTestUser()->getUser() ); | ||
$updater->setContent( 'main', $content ); | ||
$updater->saveRevision( CommentStoreComment::newUnsavedComment( 'Test' ) ); | ||
|
||
return $page->getTitle(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/phpunit/integration/SpecialCategoryIntersectionSearchTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters