mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
Add first basic tests for ThreadItemStore::find*() methods
Just covering the basic scenarios of having comments on the page and archiving them. Bug: T356575 Change-Id: I9022b0a7cf3b02bd9f2f2d5605823eec21b92642
This commit is contained in:
parent
9f650c92ee
commit
0f6bdcf9cb
|
@ -4,7 +4,9 @@ namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|||
|
||||
use ExtensionRegistry;
|
||||
use ImportStringSource;
|
||||
use MediaWiki\Extension\DiscussionTools\ThreadItemStore;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Title\TitleValue;
|
||||
use TestUser;
|
||||
|
||||
/**
|
||||
|
@ -14,10 +16,9 @@ use TestUser;
|
|||
*/
|
||||
class ThreadItemStoreTest extends IntegrationTestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider provideInsertCases
|
||||
*/
|
||||
public function testInsertThreadItems( string $dir ): void {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
if (
|
||||
$this->db->getType() === 'mysql' &&
|
||||
strpos( $this->db->getSoftwareLink(), 'MySQL' ) &&
|
||||
|
@ -29,7 +30,9 @@ class ThreadItemStoreTest extends IntegrationTestCase {
|
|||
if ( ExtensionRegistry::getInstance()->isLoaded( 'Liquid Threads' ) ) {
|
||||
$this->setMwGlobals( 'wgLqtTalkPages', false );
|
||||
}
|
||||
}
|
||||
|
||||
private function importTestCase( string $dir ) {
|
||||
// Create users for the imported revisions
|
||||
new TestUser( 'X' );
|
||||
new TestUser( 'Y' );
|
||||
|
@ -43,6 +46,13 @@ class ThreadItemStoreTest extends IntegrationTestCase {
|
|||
// `true` means to assign edits to the users we created above
|
||||
$importer->setUsernamePrefix( 'import', true );
|
||||
$importer->doImport();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInsertCases
|
||||
*/
|
||||
public function testInsertThreadItems( string $dir ): void {
|
||||
$this->importTestCase( $dir );
|
||||
|
||||
// Check that expected data has been stored in the database
|
||||
$expected = [];
|
||||
|
@ -93,4 +103,66 @@ class ThreadItemStoreTest extends IntegrationTestCase {
|
|||
[ 'cases/ThreadItemStore/8indistinguishable-comments-same-page' ],
|
||||
];
|
||||
}
|
||||
|
||||
public function testFindSimple(): void {
|
||||
$this->importTestCase( 'cases/ThreadItemStore/1simple-example' );
|
||||
/** @var ThreadItemStore $itemStore */
|
||||
$itemStore = $this->getServiceContainer()->getService( 'DiscussionTools.ThreadItemStore' );
|
||||
|
||||
// BY NAME
|
||||
// Valid name finds the item
|
||||
$set = $itemStore->findNewestRevisionsByName( 'c-Y-20220720010200' );
|
||||
$this->assertCount( 1, $set );
|
||||
$this->assertEquals( 'ThreadItemStore1', $set[0]->getPage()->getDBkey() );
|
||||
$this->assertEquals( 'c-Y-20220720010200', $set[0]->getName() );
|
||||
|
||||
// Wrong name - no results
|
||||
$set = $itemStore->findNewestRevisionsByName( 'c-blah' );
|
||||
$this->assertCount( 0, $set );
|
||||
|
||||
// BY ID
|
||||
// Valid ID finds the item
|
||||
$set = $itemStore->findNewestRevisionsById( 'c-Y-20220720010200-X-20220720010100' );
|
||||
$this->assertCount( 1, $set );
|
||||
$this->assertEquals( 'ThreadItemStore1', $set[0]->getPage()->getDBkey() );
|
||||
$this->assertEquals( 'c-Y-20220720010200-X-20220720010100', $set[0]->getId() );
|
||||
|
||||
// Wrong ID - no results
|
||||
$set = $itemStore->findNewestRevisionsById( 'c-blah' );
|
||||
$this->assertCount( 0, $set );
|
||||
|
||||
// BY HEADING
|
||||
// Valid heading + page title finds the item
|
||||
$page = $this->getServiceContainer()->getPageStore()->getPageByName( NS_TALK, 'ThreadItemStore1' );
|
||||
$set = $itemStore->findNewestRevisionsByHeading( 'A', $page->getId(), TitleValue::newFromPage( $page ) );
|
||||
$this->assertCount( 1, $set );
|
||||
$this->assertEquals( 'ThreadItemStore1', $set[0]->getPage()->getDBkey() );
|
||||
|
||||
// Wrong heading - no results
|
||||
$set = $itemStore->findNewestRevisionsByHeading( 'blah', $page->getId(), TitleValue::newFromPage( $page ) );
|
||||
$this->assertCount( 0, $set );
|
||||
|
||||
// Wrong page - but we still get a result, since it's unique (case 3.)
|
||||
$set = $itemStore->findNewestRevisionsByHeading( 'A', 12345, new TitleValue( NS_TALK, 'Blah' ) );
|
||||
$this->assertCount( 1, $set );
|
||||
}
|
||||
|
||||
public function testFindArchived(): void {
|
||||
$this->importTestCase( 'cases/ThreadItemStore/2archived-section' );
|
||||
/** @var ThreadItemStore $itemStore */
|
||||
$itemStore = $this->getServiceContainer()->getService( 'DiscussionTools.ThreadItemStore' );
|
||||
|
||||
// Valid name finds the original item in old revision, and the item in the archive
|
||||
$set = $itemStore->findNewestRevisionsByName( 'c-X-20220720020100' );
|
||||
$this->assertCount( 2, $set );
|
||||
|
||||
// Valid ID finds the original item in old revision, and the item in the archive
|
||||
$set = $itemStore->findNewestRevisionsById( 'c-X-20220720020100-A' );
|
||||
$this->assertCount( 2, $set );
|
||||
|
||||
// Valid heading + page title finds the original item in old revision, and the item in the archive
|
||||
$page = $this->getServiceContainer()->getPageStore()->getPageByName( NS_TALK, 'ThreadItemStore2' );
|
||||
$set = $itemStore->findNewestRevisionsByHeading( 'A', $page->getId(), TitleValue::newFromPage( $page ) );
|
||||
$this->assertCount( 2, $set );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue