2016-12-02 15:55:26 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Linter\Test;
|
|
|
|
|
2022-02-08 23:19:12 +00:00
|
|
|
use ContentHandler;
|
2022-09-07 01:48:18 +00:00
|
|
|
use Exception;
|
2022-02-08 23:19:12 +00:00
|
|
|
use MediaWiki\Linter\RecordLintJob;
|
2016-12-02 15:55:26 +00:00
|
|
|
use MediaWiki\Linter\SpecialLintErrors;
|
2024-04-04 22:10:50 +00:00
|
|
|
use MediaWiki\Page\PageReference;
|
2023-05-19 10:24:44 +00:00
|
|
|
use MediaWiki\Request\FauxRequest;
|
2023-08-19 04:17:17 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-09-07 01:48:18 +00:00
|
|
|
use SpecialPageTestBase;
|
2016-12-02 15:55:26 +00:00
|
|
|
|
|
|
|
/**
|
2022-09-07 01:48:18 +00:00
|
|
|
* @covers \MediaWiki\Linter\SpecialLintErrors
|
2023-09-04 17:21:08 +00:00
|
|
|
*
|
|
|
|
* @group Database
|
2016-12-02 15:55:26 +00:00
|
|
|
*/
|
2022-09-07 01:48:18 +00:00
|
|
|
class SpecialLintErrorsTest extends SpecialPageTestBase {
|
2016-12-02 15:55:26 +00:00
|
|
|
|
2024-04-04 22:55:43 +00:00
|
|
|
private function newDatabase( int $pageId, ?int $namespaceId = null ) {
|
|
|
|
$services = $this->getServiceContainer();
|
|
|
|
$databaseFactory = $services->get( 'Linter.DatabaseFactory' );
|
|
|
|
return $databaseFactory->newDatabase( $pageId, $namespaceId );
|
|
|
|
}
|
|
|
|
|
2024-04-04 22:10:50 +00:00
|
|
|
private function newRecordLintJob( PageReference $page, array $params ) {
|
|
|
|
$services = $this->getServiceContainer();
|
|
|
|
return new RecordLintJob(
|
|
|
|
$page,
|
|
|
|
$params,
|
2024-04-05 02:20:45 +00:00
|
|
|
$services->get( 'Linter.TotalsLookup' ),
|
2024-04-04 22:55:43 +00:00
|
|
|
$services->get( 'Linter.DatabaseFactory' )
|
2024-04-04 22:10:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-02 15:55:26 +00:00
|
|
|
protected function newSpecialPage() {
|
2024-04-04 21:41:29 +00:00
|
|
|
$services = $this->getServiceContainer();
|
|
|
|
return new SpecialLintErrors(
|
|
|
|
$services->getNamespaceInfo(),
|
2024-04-04 22:55:43 +00:00
|
|
|
$services->getTitleParser(),
|
|
|
|
$services->get( 'Linter.CategoryManager' ),
|
2024-04-05 02:20:45 +00:00
|
|
|
$services->get( 'Linter.TotalsLookup' ),
|
2024-04-04 22:55:43 +00:00
|
|
|
$services->get( 'Linter.DatabaseFactory' )
|
2024-04-04 21:41:29 +00:00
|
|
|
);
|
2016-12-02 15:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testExecute() {
|
2024-04-04 22:55:43 +00:00
|
|
|
$categoryManager =
|
|
|
|
$this->getServiceContainer()->get( 'Linter.CategoryManager' );
|
|
|
|
$category = $categoryManager->getVisibleCategories()[0];
|
2016-12-02 15:55:26 +00:00
|
|
|
|
|
|
|
// Basic
|
|
|
|
$html = $this->executeSpecialPage( '', null, 'qqx' )[0];
|
2020-07-09 15:00:27 +00:00
|
|
|
$this->assertStringContainsString( '(linterrors-summary)', $html );
|
|
|
|
$this->assertStringContainsString( "(linter-category-$category)", $html );
|
2016-12-02 15:55:26 +00:00
|
|
|
|
2020-07-09 15:00:27 +00:00
|
|
|
$this->assertStringContainsString(
|
2016-12-02 15:55:26 +00:00
|
|
|
"(linter-category-$category-desc)",
|
|
|
|
$this->executeSpecialPage( $category, null, 'qqx' )[0]
|
|
|
|
);
|
2022-08-25 20:15:57 +00:00
|
|
|
|
|
|
|
$this->overrideConfigValue( 'LinterUserInterfaceTagAndTemplateStage', true );
|
|
|
|
// Verify new tag and template interfaces are present
|
|
|
|
$html = $this->executeSpecialPage( 'misnested-tag', null, 'qqx' )[0];
|
|
|
|
$this->assertStringContainsString( 'linter-form-template', $html );
|
|
|
|
$this->assertStringContainsString( 'linter-form-tag', $html );
|
2016-12-02 15:55:26 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 23:19:12 +00:00
|
|
|
/**
|
2022-03-10 19:48:19 +00:00
|
|
|
* @param string $titleText
|
|
|
|
* @param int|null $ns
|
2022-02-08 23:19:12 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2023-09-04 17:44:48 +00:00
|
|
|
private function createTitleAndPage(
|
|
|
|
string $titleText = 'SpecialLintErrorsTest test page',
|
|
|
|
?int $ns = null
|
|
|
|
): array {
|
|
|
|
$ns ??= $this->getDefaultWikitextNS();
|
2022-02-08 23:19:12 +00:00
|
|
|
$title = Title::newFromText( $titleText, $ns );
|
2023-09-04 17:44:48 +00:00
|
|
|
$page = $this->getExistingTestPage( $title );
|
2022-02-08 23:19:12 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
'title' => $title,
|
|
|
|
'pageID' => $page->getRevisionRecord()->getPageId(),
|
|
|
|
'revID' => $page->getRevisionRecord()->getID(),
|
|
|
|
'page' => $page,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testContentModelChange() {
|
|
|
|
$error = [
|
|
|
|
'type' => 'obsolete-tag',
|
|
|
|
'location' => [ 0, 10 ],
|
|
|
|
'params' => [],
|
|
|
|
'dbid' => null,
|
|
|
|
];
|
|
|
|
$titleAndPage = $this->createTitleAndPage();
|
2024-04-04 22:10:50 +00:00
|
|
|
$job = $this->newRecordLintJob( $titleAndPage['title'], [
|
2022-02-08 23:19:12 +00:00
|
|
|
'errors' => [ $error ],
|
|
|
|
'revision' => $titleAndPage['revID']
|
|
|
|
] );
|
|
|
|
$this->assertTrue( $job->run() );
|
|
|
|
|
2024-04-04 22:55:43 +00:00
|
|
|
$db = $this->newDatabase( $titleAndPage['pageID'] );
|
2022-02-08 23:19:12 +00:00
|
|
|
|
|
|
|
$errorsFromDb = array_values( $db->getForPage() );
|
|
|
|
$this->assertCount( 1, $errorsFromDb );
|
|
|
|
|
|
|
|
$cssText = 'css content model change test page content';
|
|
|
|
$content = ContentHandler::makeContent(
|
|
|
|
$cssText,
|
|
|
|
$titleAndPage['title'],
|
|
|
|
'css'
|
|
|
|
);
|
|
|
|
$page = $titleAndPage['page'];
|
2023-09-04 17:44:48 +00:00
|
|
|
$this->editPage(
|
|
|
|
$page,
|
2022-02-08 23:19:12 +00:00
|
|
|
$content,
|
|
|
|
"update with css content model to trigger onRevisionFromEditComplete hook"
|
|
|
|
);
|
|
|
|
|
|
|
|
$errorsFromDb = array_values( $db->getForPage() );
|
|
|
|
$this->assertCount( 0, $errorsFromDb );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testContentModelChangeWithBlankPage() {
|
|
|
|
$error = [
|
|
|
|
'type' => 'obsolete-tag',
|
|
|
|
'location' => [ 0, 10 ],
|
|
|
|
'params' => [],
|
|
|
|
'dbid' => null,
|
|
|
|
];
|
|
|
|
$titleAndPage = $this->createTitleAndPage();
|
2024-04-04 22:10:50 +00:00
|
|
|
$job = $this->newRecordLintJob( $titleAndPage['title'], [
|
2022-02-08 23:19:12 +00:00
|
|
|
'errors' => [ $error ],
|
|
|
|
'revision' => $titleAndPage['revID']
|
|
|
|
] );
|
|
|
|
$this->assertTrue( $job->run() );
|
|
|
|
|
2024-04-04 22:55:43 +00:00
|
|
|
$db = $this->newDatabase( $titleAndPage['pageID'] );
|
2022-02-08 23:19:12 +00:00
|
|
|
|
|
|
|
$errorsFromDb = array_values( $db->getForPage() );
|
|
|
|
$this->assertCount( 1, $errorsFromDb );
|
|
|
|
|
2023-09-04 17:44:48 +00:00
|
|
|
// This test recreates the bug mentioned in T280193 of not
|
2022-02-08 23:19:12 +00:00
|
|
|
// calling the onRevisionFromEditComplete hook with the "mw-contentmodelchange"
|
|
|
|
// tag set when the new content text is literally blank.
|
|
|
|
$blankText = '';
|
|
|
|
$content = ContentHandler::makeContent(
|
|
|
|
$blankText,
|
|
|
|
$titleAndPage['title'],
|
|
|
|
'text'
|
|
|
|
);
|
|
|
|
$page = $titleAndPage['page'];
|
2023-09-04 17:44:48 +00:00
|
|
|
$this->editPage(
|
|
|
|
$page,
|
2022-02-08 23:19:12 +00:00
|
|
|
$content,
|
|
|
|
"update with blank text content model to trigger onRevisionFromEditComplete hook"
|
|
|
|
);
|
|
|
|
|
|
|
|
$errorsFromDb = array_values( $db->getForPage() );
|
2022-02-28 22:48:01 +00:00
|
|
|
$this->assertCount( 0, $errorsFromDb );
|
2022-02-08 23:19:12 +00:00
|
|
|
}
|
2022-03-10 19:48:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $pageData
|
|
|
|
*/
|
|
|
|
private function createPagesWithLintErrorsFromData( array $pageData ) {
|
|
|
|
foreach ( $pageData as $data ) {
|
|
|
|
$titleAndPage = $this->createTitleAndPage( $data[ 'name' ], $data[ 'ns' ] );
|
|
|
|
$errors = [];
|
|
|
|
foreach ( $data[ 'lintErrors' ] as $lintError ) {
|
|
|
|
$errors[] = [
|
|
|
|
'type' => $lintError[ 'type' ],
|
|
|
|
'location' => $lintError[ 'location' ],
|
|
|
|
'params' => [],
|
|
|
|
'dbid' => null
|
|
|
|
];
|
|
|
|
}
|
2024-04-04 22:10:50 +00:00
|
|
|
$job = $this->newRecordLintJob( $titleAndPage[ 'title' ], [
|
2022-03-10 19:48:19 +00:00
|
|
|
'errors' => $errors,
|
|
|
|
'revision' => $titleAndPage[ 'revID' ]
|
|
|
|
] );
|
|
|
|
$job->run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function createTitleAndPageAndLintErrorData(): array {
|
|
|
|
$pageData = [];
|
|
|
|
$pageData[] = [ 'name' => 'Lint Error One', 'ns' => 0,
|
2022-09-07 01:48:18 +00:00
|
|
|
'lintErrors' => [
|
|
|
|
[ 'type' => 'obsolete-tag', 'location' => [ 0, 10 ] ],
|
|
|
|
[ 'type' => 'misnested-tag', 'location' => [ 20, 30 ] ]
|
|
|
|
]
|
2022-03-10 19:48:19 +00:00
|
|
|
];
|
|
|
|
$pageData[] = [ 'name' => 'LintErrorTwo', 'ns' => 3,
|
|
|
|
'lintErrors' => [ [ 'type' => 'obsolete-tag', 'location' => [ 0, 10 ] ] ]
|
|
|
|
];
|
|
|
|
$pageData[] = [ 'name' => 'NotANamespace:LintErrorThree', 'ns' => 0,
|
2022-09-07 01:48:18 +00:00
|
|
|
'lintErrors' => [
|
|
|
|
[ 'type' => 'obsolete-tag', 'location' => [ 0, 10 ] ],
|
|
|
|
[ 'type' => 'misnested-tag', 'location' => [ 20, 30 ] ]
|
|
|
|
]
|
2022-03-10 19:48:19 +00:00
|
|
|
];
|
|
|
|
$pageData[] = [ 'name' => 'NotANamespace:LintErrorFour', 'ns' => 0,
|
2022-09-07 01:48:18 +00:00
|
|
|
'lintErrors' => [
|
|
|
|
[ 'type' => 'obsolete-tag', 'location' => [ 0, 10 ] ],
|
|
|
|
[ 'type' => 'misnested-tag', 'location' => [ 20, 30 ] ]
|
|
|
|
]
|
2022-03-10 19:48:19 +00:00
|
|
|
];
|
|
|
|
$pageData[] = [ 'name' => 'Some other page', 'ns' => 0,
|
|
|
|
'lintErrors' => [ [ 'type' => 'bogus-image-options', 'location' => [ 30, 40 ] ] ]
|
|
|
|
];
|
|
|
|
$pageData[] = [ 'name' => 'FooBar:ErrorFive', 'ns' => 3,
|
|
|
|
'lintErrors' => [ [ 'type' => 'obsolete-tag', 'location' => [ 0, 10 ] ] ]
|
|
|
|
];
|
2023-06-13 22:26:52 +00:00
|
|
|
$pageData[] = [ 'name' => 'ErrorSix', 'ns' => 3,
|
|
|
|
'lintErrors' => [
|
|
|
|
[ 'type' => 'obsolete-tag', 'location' => [ 0, 10 ] ],
|
|
|
|
[ 'type' => 'misnested-tag', 'location' => [ 20, 30 ] ]
|
|
|
|
]
|
|
|
|
];
|
2022-03-10 19:48:19 +00:00
|
|
|
return $pageData;
|
|
|
|
}
|
|
|
|
|
2023-06-13 22:26:52 +00:00
|
|
|
// namespaces specified: all, Main, Talk and User talk (defined in config as null, int 0, 1 and 3)
|
2022-03-10 19:48:19 +00:00
|
|
|
// Titles exact matched and searched by tests include: empty - "", "L", "Lint Error One", "User Talk:L",
|
|
|
|
// "User talk:LintErrorTwo", "NotANamespace:L", "NotANamespace:LintErrorThree", "NotANamespace:LintErrorFour"
|
|
|
|
//
|
|
|
|
// Tests are grouped into three categories: empty title for all tests, namespace all for half and User talk for
|
2023-06-13 22:26:52 +00:00
|
|
|
// the rest, with exact match booleans cycling.
|
2022-03-10 19:48:19 +00:00
|
|
|
//
|
|
|
|
// The second group is similar, the title being either "NotANamespace:L" or "NotANamespace:LintErrorThree" or
|
2023-06-13 22:26:52 +00:00
|
|
|
// "NotANamespace:LintErrorFour" with half namespace set all or User talk and exact match booleans
|
2022-03-10 19:48:19 +00:00
|
|
|
// cycling.
|
|
|
|
//
|
|
|
|
// The third group is composed of tests against main, talk, User Talk and all namespaces. This test also includes
|
|
|
|
// titles with and without namespace prefixes, some which match the drop-down namespace and some which conflict
|
2023-06-13 22:26:52 +00:00
|
|
|
// depending on the combination of namespace definitions.
|
2022-03-10 19:48:19 +00:00
|
|
|
//
|
|
|
|
// The forth test covers the use of ':title' (main namespace) as the search text to ensure 'all' and 'main'
|
|
|
|
// are handled properly.
|
|
|
|
//
|
2023-06-13 22:26:52 +00:00
|
|
|
// The fifth test covers the user of an editor defined, (non wiki defined namespace with a namespace ID), but
|
2022-03-10 19:48:19 +00:00
|
|
|
// which was created in the User_talk wiki defined namespace ID 3.
|
|
|
|
//
|
|
|
|
// The sixth test covers accessing the search mechanism through the misnested-tag subpage. It verifies that
|
|
|
|
// LintErrorTwo, which has no misnested-tag errors is not in any search results, but other searches are as expected.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|null $subpage
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function createLinterSearchTestConfigurations( ?string $subpage ): array {
|
|
|
|
$testConfigurations = [];
|
|
|
|
if ( $subpage !== 'misnested-tag' ) {
|
|
|
|
$testConfigurations[ 1 ] = [
|
|
|
|
'namespaces' => [ 0, 3 ],
|
|
|
|
'titles' => [ '' ],
|
2023-06-13 22:26:52 +00:00
|
|
|
'cases' => [ [ 'iterations' => [ 0, 1, 2, 3 ], 'message' => 'linter-invalid-title' ]
|
2022-03-10 19:48:19 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$testConfigurations[ 2 ] = [
|
|
|
|
'namespaces' => [ 0, 3 ],
|
|
|
|
'titles' => [ 'NotANamespace:L', 'NotANamespace:LintErrorFour' ],
|
|
|
|
'cases' => [
|
2023-06-13 22:26:52 +00:00
|
|
|
[ 'iterations' => [ 1 ], 'message' => 'NotANamespace:LintErrorThree' ],
|
|
|
|
[ 'iterations' => [ 1, 2, 3 ], 'message' => 'NotANamespace:LintErrorFour' ],
|
|
|
|
[ 'iterations' => [ 0, 4, 5, 6, 7 ], 'message' => 'table_pager_empty' ]
|
2022-03-10 19:48:19 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$testConfigurations[ 3 ] = [
|
2024-03-25 05:13:49 +00:00
|
|
|
'namespaces' => [ 0, 1, 3 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'titles' => [ 'L', 'Lint Error One', 'LintErrorTwo', 'User talk:L', 'User talk:LintErrorTwo',
|
|
|
|
'Talk:L' ],
|
|
|
|
'cases' => [
|
2024-03-25 05:13:49 +00:00
|
|
|
[ 'iterations' => [ 1, 2, 3 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'message' => 'Lint Error One' ],
|
2024-03-25 05:13:49 +00:00
|
|
|
[ 'iterations' => [ 25, 28, 29, 31, 32, 33 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'message' => 'LintErrorTwo' ],
|
2024-03-25 05:13:49 +00:00
|
|
|
[ 'iterations' => [ 0, 4, 5, 12, 13, 14, 15, 16, 17, 22, 23, 24, 26, 27, 30 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'message' => 'table_pager_empty' ],
|
2023-06-13 22:26:52 +00:00
|
|
|
[ 'iterations' => [ 6, 7, 8, 9, 10, 11, 18, 19, 20, 21, 34, 35 ],
|
|
|
|
'message' => 'linter-namespace-mismatch' ]
|
2022-03-10 19:48:19 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
$testConfigurations[ 4 ] = [
|
2024-03-25 05:13:49 +00:00
|
|
|
'namespaces' => [ 0, 3 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'titles' => [ ':Lint Error One' ],
|
|
|
|
'cases' => [
|
2024-03-25 05:13:49 +00:00
|
|
|
[ 'iterations' => [ 0, 1 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'message' => 'Lint Error One' ],
|
2023-06-13 22:26:52 +00:00
|
|
|
[ 'iterations' => [ 2, 3 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'message' => 'linter-namespace-mismatch' ]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$testConfigurations[ 5 ] = [
|
2024-03-25 05:13:49 +00:00
|
|
|
'namespaces' => [ 0, 3 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'titles' => [ 'FooBar:ErrorFive' ],
|
|
|
|
'cases' => [
|
2024-03-25 05:13:49 +00:00
|
|
|
[ 'iterations' => [ 2, 3 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'message' => 'FooBar:ErrorFive' ],
|
2023-06-13 22:26:52 +00:00
|
|
|
[ 'iterations' => [ 0, 1 ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'message' => 'table_pager_empty' ],
|
|
|
|
]
|
|
|
|
];
|
2023-06-13 22:26:52 +00:00
|
|
|
// check both NS0 and NS3 at the same time
|
2022-03-10 19:48:19 +00:00
|
|
|
$testConfigurations[ 6 ] = [
|
2023-06-13 22:26:52 +00:00
|
|
|
'namespaces' => [ [ 0, 3 ] ],
|
|
|
|
'titles' => [ 'L', 'Lint Error One', 'LintErrorTwo' ],
|
|
|
|
'cases' => [
|
|
|
|
[ 'iterations' => [ 1, 2, 3 ],
|
|
|
|
'message' => 'Lint Error One' ],
|
|
|
|
[ 'iterations' => [ 1, 4, 5 ],
|
|
|
|
'message' => 'LintErrorTwo' ],
|
|
|
|
[ 'iterations' => [ 0 ],
|
|
|
|
'message' => 'table_pager_empty' ],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$testConfigurations[ 7 ] = [
|
2022-03-10 19:48:19 +00:00
|
|
|
'namespaces' => [ 0, 3 ],
|
2023-06-13 22:26:52 +00:00
|
|
|
'titles' => [ 'L', 'Lint Error One', 'NotANamespace:L' ],
|
2022-03-10 19:48:19 +00:00
|
|
|
'cases' => [
|
2023-06-13 22:26:52 +00:00
|
|
|
[ 'iterations' => [ 1, 2, 3 ], 'message' => 'title="Lint Error One">' ],
|
2022-03-10 19:48:19 +00:00
|
|
|
[ 'iterations' => [], 'message' => 'title="LintErrorTwo">' ],
|
2023-06-13 22:26:52 +00:00
|
|
|
[ 'iterations' => [ 5 ], 'message' => 'title="NotANamespace:LintErrorThree">' ],
|
|
|
|
[ 'iterations' => [ 5 ], 'message' => 'title="NotANamespace:LintErrorFour">' ],
|
|
|
|
[ 'iterations' => [ 0, 4, 6, 7, 8, 9, 10, 11 ], 'message' => '(table_pager_empty)' ]
|
2022-03-10 19:48:19 +00:00
|
|
|
]
|
|
|
|
];
|
2023-06-13 22:26:52 +00:00
|
|
|
$testConfigurations[ 8 ] = [
|
|
|
|
'namespaces' => [ [ 0, 3 ] ],
|
|
|
|
'titles' => [ 'L', 'Lint Error One', 'NotANamespace:L', 'ErrorSix' ],
|
|
|
|
'cases' => [
|
|
|
|
[ 'iterations' => [ 1, 2, 3 ], 'message' => 'title="Lint Error One">' ],
|
|
|
|
[ 'iterations' => [], 'message' => 'title="LintErrorTwo">' ],
|
|
|
|
[ 'iterations' => [ 5 ], 'message' => 'title="NotANamespace:LintErrorThree">' ],
|
|
|
|
[ 'iterations' => [ 5 ], 'message' => 'title="NotANamespace:LintErrorFour">' ],
|
|
|
|
[ 'iterations' => [ 6, 7 ], 'message' => ':ErrorSix">' ],
|
|
|
|
[ 'iterations' => [ 0, 4 ], 'message' => '(table_pager_empty)' ]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2022-03-10 19:48:19 +00:00
|
|
|
}
|
|
|
|
return $testConfigurations;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $testConfig
|
|
|
|
* @param string|null $subPage
|
|
|
|
* @param string $titleSearchString
|
|
|
|
* @return void
|
2022-09-07 01:48:18 +00:00
|
|
|
* @throws Exception
|
2022-03-10 19:48:19 +00:00
|
|
|
*/
|
|
|
|
private function performLinterSearchTests( array $testConfig, ?string $subPage, string $titleSearchString ): void {
|
2023-06-13 22:26:52 +00:00
|
|
|
foreach ( $testConfig as $groupIndex => $group ) {
|
2022-03-10 19:48:19 +00:00
|
|
|
$testIndex = 0;
|
|
|
|
foreach ( $group[ 'namespaces' ] as $namespace ) {
|
|
|
|
foreach ( $group[ 'titles' ] as $title ) {
|
2023-06-13 22:26:52 +00:00
|
|
|
$exact = true;
|
2022-03-10 19:48:19 +00:00
|
|
|
do {
|
2023-06-13 22:26:52 +00:00
|
|
|
if ( $namespace === null ) {
|
|
|
|
$params = [ $titleSearchString => $title, 'exactmatch' => $exact ];
|
|
|
|
} else {
|
|
|
|
if ( is_array( $namespace ) ) {
|
|
|
|
// simulate the same URL string that the multi namespace widget produces
|
|
|
|
$namespaces = implode( "\r\n", $namespace );
|
|
|
|
$params = array_merge( [ 'wpNamespaceRestrictions' => $namespaces ],
|
|
|
|
[ $titleSearchString => $title, 'exactmatch' => $exact ] );
|
|
|
|
} else {
|
|
|
|
$params = [ 'wpNamespaceRestrictions' => $namespace, $titleSearchString => $title,
|
|
|
|
'exactmatch' => $exact ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$webRequest = new FauxRequest( $params );
|
|
|
|
$html = $this->executeSpecialPage( $subPage, $webRequest, 'qqx' )[ 0 ];
|
2022-03-10 19:48:19 +00:00
|
|
|
|
2023-06-13 22:26:52 +00:00
|
|
|
foreach ( $group[ 'cases' ] as $caseIndex => $case ) {
|
|
|
|
$exactString = [ 'prefix', 'exact' ][ $exact ];
|
|
|
|
$message = $case[ 'message' ];
|
2024-03-25 05:13:49 +00:00
|
|
|
$descriptionNamespace = implode( ',', (array)$namespace );
|
2023-06-13 22:26:52 +00:00
|
|
|
$description = "On group [$groupIndex], namespace [$descriptionNamespace], " .
|
|
|
|
"case [$caseIndex], iteration [$testIndex] " .
|
|
|
|
"for a [$exactString] match with search title [$title] and test text [$message] ";
|
2022-03-10 19:48:19 +00:00
|
|
|
|
2023-06-13 22:26:52 +00:00
|
|
|
if ( in_array( $testIndex, $case[ 'iterations' ] ) ) {
|
|
|
|
if ( empty( $debugTests ) ) {
|
2022-03-10 19:48:19 +00:00
|
|
|
$this->assertStringContainsString( $message, $html, $description .
|
|
|
|
"was not found." );
|
|
|
|
} else {
|
2023-06-13 22:26:52 +00:00
|
|
|
// code to aid in debugging test conditions
|
|
|
|
if ( !str_contains( $html, $message ) ) {
|
|
|
|
echo $description . "was not found.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( empty( $debugTests ) ) {
|
2022-03-10 19:48:19 +00:00
|
|
|
$this->assertStringNotContainsString( $message, $html, $description .
|
|
|
|
"was not supposed to be found." );
|
2023-06-13 22:26:52 +00:00
|
|
|
} else {
|
|
|
|
// code to aid in debugging test conditions
|
|
|
|
if ( str_contains( $html, $message ) ) {
|
|
|
|
echo $description . "was not supposed to be found.\n";
|
|
|
|
}
|
2022-03-10 19:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-13 22:26:52 +00:00
|
|
|
}
|
|
|
|
$testIndex++;
|
|
|
|
$exact = !$exact;
|
|
|
|
} while ( !$exact );
|
2022-03-10 19:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-07 01:48:18 +00:00
|
|
|
* @throws Exception
|
2022-03-10 19:48:19 +00:00
|
|
|
*/
|
|
|
|
public function testLinterSearchVariations(): void {
|
|
|
|
$this->createTitleAndPage();
|
|
|
|
$pageData = $this->createTitleAndPageAndLintErrorData();
|
|
|
|
$this->createPagesWithLintErrorsFromData( $pageData );
|
|
|
|
|
|
|
|
$testConfigurations = $this->createLinterSearchTestConfigurations( null );
|
|
|
|
$this->performLinterSearchTests( $testConfigurations, null, 'titlesearch' );
|
|
|
|
|
|
|
|
$testConfigurations = $this->createLinterSearchTestConfigurations( 'misnested-tag' );
|
|
|
|
$this->performLinterSearchTests( $testConfigurations, 'misnested-tag', 'titlecategorysearch' );
|
|
|
|
}
|
2016-12-02 15:55:26 +00:00
|
|
|
}
|