getDefaultWikitextNS(); $title = Title::newFromText( $titleText, $ns ); $user = User::newFromName( $userName ); if ( $user->getId() === 0 ) { $user->addToDatabase(); } $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); $content = ContentHandler::makeContent( $baseText, $title ); $page->doUserEditContent( $content, $user, "base text for test" ); return [ 'title' => $title, 'pageID' => $page->getRevisionRecord()->getPageId(), 'revID' => $page->getRevisionRecord()->getID() ]; } /** * Get just the lint error linter_tag field value for a page * * @param int $pageId * @return stdClass|bool */ private static function getTagForPage( int $pageId ) { return Database::getDBConnectionRef( DB_REPLICA )->selectRow( 'linter', [ 'linter_tag' ], [ 'linter_page' => $pageId ], __METHOD__ ); } /** * Get just the lint error linter_template field value for a page * * @param int $pageId * @return stdClass|bool */ private static function getTemplateForPage( int $pageId ) { return Database::getDBConnectionRef( DB_REPLICA )->selectRow( 'linter', [ 'linter_template' ], [ 'linter_page' => $pageId ], __METHOD__ ); } public function testRun() { $error = [ 'type' => 'fostered', 'location' => [ 0, 10 ], 'params' => [], 'dbid' => null, ]; $titleAndPage = $this->createTitleAndPage( 'TestPage' ); $job = new RecordLintJob( $titleAndPage[ 'title' ], [ 'errors' => [ $error ], 'revision' => $titleAndPage[ 'revID' ] ] ); $this->assertTrue( $job->run() ); $db = new Database( $titleAndPage[ 'pageID' ] ); /** @var LintError[] $errorsFromDb */ $errorsFromDb = array_values( $db->getForPage() ); $this->assertCount( 1, $errorsFromDb ); $this->assertInstanceOf( LintError::class, $errorsFromDb[ 0 ] ); $this->assertEquals( $error[ 'type' ], $errorsFromDb[ 0 ]->category ); $this->assertEquals( $error[ 'location' ], $errorsFromDb[ 0 ]->location ); $this->assertEquals( $error[ 'params' ], $errorsFromDb[ 0 ]->params ); } public function testWriteTagAndTemplate() { $this->overrideConfigValue( 'LinterWriteTagAndTemplateColumnsStage', true ); $error = [ 'type' => 'obsolete-tag', 'location' => [ 0, 10 ], 'params' => [ "name" => "center", "templateInfo" => [ "name" => "Template:Echo" ] ], 'dbid' => null, ]; $titleAndPage = $this->createTitleAndPage( 'TestPage2' ); $job = new RecordLintJob( $titleAndPage[ 'title' ], [ 'errors' => [ $error ], 'revision' => $titleAndPage[ 'revID' ] ] ); $this->assertTrue( $job->run() ); $pageId = $titleAndPage[ 'pageID' ]; $db = new Database( $pageId ); $errorsFromDb = array_values( $db->getForPage() ); $this->assertCount( 1, $errorsFromDb ); $this->assertInstanceOf( LintError::class, $errorsFromDb[0] ); $this->assertEquals( $error[ 'type' ], $errorsFromDb[0]->category ); $this->assertEquals( $error[ 'location' ], $errorsFromDb[0]->location ); $this->assertEquals( $error[ 'params' ], $errorsFromDb[0]->params ); $tag = self::getTagForPage( $pageId )->linter_tag ?? ''; $this->assertEquals( $error[ 'params' ][ 'name' ], $tag ); $template = self::getTemplateForPage( $pageId )->linter_template ?? ''; $this->assertEquals( $error[ 'params' ][ 'templateInfo' ][ 'name' ], $template ); } public function testDropInlineMediaCaptionLints() { $error = [ 'type' => 'inline-media-caption', 'location' => [ 0, 10 ], 'params' => [], 'dbid' => null, ]; $titleAndPage = $this->createTitleAndPage( 'TestPage3' ); $job = new RecordLintJob( $titleAndPage['title'], [ 'errors' => [ $error ], 'revision' => $titleAndPage['revID'] ] ); $this->assertTrue( $job->run() ); /** @var LintError[] $errorsFromDb */ $errorsFromDb = array_values( ( new Database( $titleAndPage['pageID'] ) )->getForPage() ); $this->assertCount( 0, $errorsFromDb ); } }