Файловый менеджер - Редактировать - /var/www/html/cache.zip
Ðазад
PK ! �wɤ�: �: LinkCacheTest.phpnu �Iw�� <?php use MediaWiki\Cache\LinkCache; use MediaWiki\Page\PageReference; use MediaWiki\Page\PageReferenceValue; use MediaWiki\Title\Title; use MediaWiki\Title\TitleValue; use Wikimedia\ObjectCache\EmptyBagOStuff; use Wikimedia\ObjectCache\HashBagOStuff; use Wikimedia\ObjectCache\WANObjectCache; use Wikimedia\Rdbms\IDBAccessObject; /** * @group Database * @group Cache * @covers \MediaWiki\Cache\LinkCache */ class LinkCacheTest extends MediaWikiIntegrationTestCase { use LinkCacheTestTrait; private function newLinkCache( ?WANObjectCache $wanCache = null ) { if ( !$wanCache ) { $wanCache = new WANObjectCache( [ 'cache' => new EmptyBagOStuff() ] ); } return new LinkCache( $this->getServiceContainer()->getTitleFormatter(), $wanCache, $this->getServiceContainer()->getNamespaceInfo(), $this->getServiceContainer()->getDBLoadBalancer() ); } public static function providePageAndLink() { return [ [ new PageReferenceValue( NS_USER, __METHOD__, PageReference::LOCAL ) ], [ new TitleValue( NS_USER, __METHOD__ ) ] ]; } public static function providePageAndLinkAndArray() { return [ [ new PageReferenceValue( NS_USER, __METHOD__, PageReference::LOCAL ) ], [ new TitleValue( NS_USER, __METHOD__ ) ], [ [ 'page_namespace' => NS_USER, 'page_title' => __METHOD__ ] ], ]; } private function getPageRow( $offset = 0 ) { return (object)[ 'page_id' => 8 + $offset, 'page_namespace' => 0, 'page_title' => 'Test ' . $offset, 'page_len' => 18, 'page_is_redirect' => 0, 'page_latest' => 118 + $offset, 'page_content_model' => CONTENT_MODEL_TEXT, 'page_lang' => 'xyz', 'page_is_new' => 0, 'page_touched' => '20200202020202', ]; } /** * @dataProvider providePageAndLinkAndArray * @covers \MediaWiki\Cache\LinkCache::addGoodLinkObjFromRow() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkRow() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkID() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkFieldObj() * @covers \MediaWiki\Cache\LinkCache::clearLink() */ public function testAddGoodLinkObjFromRow( $page ) { $linkCache = $this->newLinkCache(); $row = $this->getPageRow(); $dbkey = is_array( $page ) ? $page['page_title'] : $page->getDBkey(); $ns = is_array( $page ) ? $page['page_namespace'] : $page->getNamespace(); $linkCache->addBadLinkObj( $page ); $linkCache->addGoodLinkObjFromRow( $page, $row ); $this->assertEquals( $row, $linkCache->getGoodLinkRow( $ns, $dbkey ) ); $this->assertSame( $row->page_id, $linkCache->getGoodLinkID( $page ) ); $this->assertFalse( $linkCache->isBadLink( $page ) ); $this->assertSame( $row->page_id, $linkCache->getGoodLinkFieldObj( $page, 'id' ) ); $this->assertSame( $row->page_len, $linkCache->getGoodLinkFieldObj( $page, 'length' ) ); $this->assertSame( $row->page_is_redirect, $linkCache->getGoodLinkFieldObj( $page, 'redirect' ) ); $this->assertSame( $row->page_latest, $linkCache->getGoodLinkFieldObj( $page, 'revision' ) ); $this->assertSame( $row->page_content_model, $linkCache->getGoodLinkFieldObj( $page, 'model' ) ); $this->assertSame( $row->page_lang, $linkCache->getGoodLinkFieldObj( $page, 'lang' ) ); $this->assertEquals( $row, $linkCache->getGoodLinkRow( $ns, $dbkey ) ); $linkCache->clearBadLink( $page ); $this->assertNotNull( $linkCache->getGoodLinkID( $page ) ); $this->assertNotNull( $linkCache->getGoodLinkFieldObj( $page, 'length' ) ); $linkCache->clearLink( $page ); $this->assertSame( 0, $linkCache->getGoodLinkID( $page ) ); $this->assertNull( $linkCache->getGoodLinkFieldObj( $page, 'length' ) ); $this->assertNull( $linkCache->getGoodLinkRow( $ns, $dbkey ) ); } /** * @covers \MediaWiki\Cache\LinkCache::addGoodLinkObjFromRow() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkRow() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkID() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkFieldObj() */ public function testAddGoodLinkObjWithAllParameters() { $linkCache = $this->getServiceContainer()->getLinkCache(); $page = new PageReferenceValue( NS_USER, __METHOD__, PageReference::LOCAL ); $this->addGoodLinkObject( 8, $page, 18, 0, 118, CONTENT_MODEL_TEXT, 'xyz' ); $row = $linkCache->getGoodLinkRow( $page->getNamespace(), $page->getDBkey() ); $this->assertEquals( 8, (int)$row->page_id ); $this->assertSame( 8, $linkCache->getGoodLinkID( $page ) ); $this->assertSame( 8, $linkCache->getGoodLinkFieldObj( $page, 'id' ) ); $this->assertSame( 18, $linkCache->getGoodLinkFieldObj( $page, 'length' ) ); $this->assertSame( 0, $linkCache->getGoodLinkFieldObj( $page, 'redirect' ) ); $this->assertSame( 118, $linkCache->getGoodLinkFieldObj( $page, 'revision' ) ); $this->assertSame( CONTENT_MODEL_TEXT, $linkCache->getGoodLinkFieldObj( $page, 'model' ) ); $this->assertSame( 'xyz', $linkCache->getGoodLinkFieldObj( $page, 'lang' ) ); } /** * @covers \MediaWiki\Cache\LinkCache::addGoodLinkObjFromRow() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkRow() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkID() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkFieldObj() */ public function testAddGoodLinkObjFromRowWithMinimalParameters() { $linkCache = $this->getServiceContainer()->getLinkCache(); $page = new PageReferenceValue( NS_USER, __METHOD__, PageReference::LOCAL ); $this->addGoodLinkObject( 8, $page ); $expectedRow = [ 'page_id' => 8, 'page_len' => -1, 'page_is_redirect' => 0, 'page_latest' => 0, 'page_content_model' => null, 'page_lang' => null, ]; $actualRow = (array)$linkCache->getGoodLinkRow( $page->getNamespace(), $page->getDBkey() ); $this->assertEquals( $expectedRow, array_intersect_key( $actualRow, $expectedRow ) ); $this->assertSame( 8, $linkCache->getGoodLinkID( $page ) ); $this->assertSame( 8, $linkCache->getGoodLinkFieldObj( $page, 'id' ) ); $this->assertSame( -1, $linkCache->getGoodLinkFieldObj( $page, 'length' ) ); $this->assertSame( 0, $linkCache->getGoodLinkFieldObj( $page, 'redirect' ) ); $this->assertSame( 0, $linkCache->getGoodLinkFieldObj( $page, 'revision' ) ); $this->assertSame( null, $linkCache->getGoodLinkFieldObj( $page, 'model' ) ); $this->assertSame( null, $linkCache->getGoodLinkFieldObj( $page, 'lang' ) ); } /** * @covers \MediaWiki\Cache\LinkCache::addGoodLinkObjFromRow() */ public function testAddGoodLinkObjFromRowWithInterwikiLink() { $linkCache = $this->getServiceContainer()->getLinkCache(); $page = new TitleValue( NS_USER, __METHOD__, '', 'acme' ); $this->addGoodLinkObject( 8, $page ); $this->assertSame( 0, $linkCache->getGoodLinkID( $page ) ); } /** * @dataProvider providePageAndLink * @covers \MediaWiki\Cache\LinkCache::addBadLinkObj() * @covers \MediaWiki\Cache\LinkCache::isBadLink() * @covers \MediaWiki\Cache\LinkCache::clearLink() */ public function testAddBadLinkObj( $key ) { $linkCache = $this->getServiceContainer()->getLinkCache(); $this->assertFalse( $linkCache->isBadLink( $key ) ); $this->addGoodLinkObject( 17, $key ); $linkCache->addBadLinkObj( $key ); $this->assertTrue( $linkCache->isBadLink( $key ) ); $this->assertSame( 0, $linkCache->getGoodLinkID( $key ) ); $linkCache->clearLink( $key ); $this->assertFalse( $linkCache->isBadLink( $key ) ); } /** * @covers \MediaWiki\Cache\LinkCache::addBadLinkObj() */ public function testAddBadLinkObjWithInterwikiLink() { $linkCache = $this->newLinkCache(); $page = new TitleValue( NS_USER, __METHOD__, '', 'acme' ); $linkCache->addBadLinkObj( $page ); $this->assertFalse( $linkCache->isBadLink( $page ) ); } /** * @covers \MediaWiki\Cache\LinkCache::addLinkObj() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkFieldObj */ public function testAddLinkObj() { $existing = $this->getExistingTestPage(); $missing = $this->getNonexistingTestPage(); $linkCache = $this->newLinkCache(); $linkCache->addLinkObj( $existing ); $linkCache->addLinkObj( $missing ); $this->assertTrue( $linkCache->isBadLink( $missing ) ); $this->assertFalse( $linkCache->isBadLink( $existing ) ); $this->assertSame( $existing->getId(), $linkCache->getGoodLinkID( $existing ) ); $this->assertTrue( $linkCache->isBadLink( $missing ) ); // Make sure nothing explodes when getting a field from a non-existing entry $this->assertNull( $linkCache->getGoodLinkFieldObj( $missing, 'length' ) ); } /** * @covers \MediaWiki\Cache\LinkCache::addLinkObj() */ public function testAddLinkObjUsesCachedInfo() { $existing = $this->getExistingTestPage(); $missing = $this->getNonexistingTestPage(); $fakeRow = $this->getPageRow( $existing->getId() + 100 ); $linkCache = $this->newLinkCache(); // pretend the existing page is missing, and the missing page exists $linkCache->addGoodLinkObjFromRow( $missing, $fakeRow ); $linkCache->addBadLinkObj( $existing ); // the LinkCache should use the cached info and not look into the database $this->assertSame( (int)$fakeRow->page_id, $linkCache->addLinkObj( $missing ) ); $this->assertSame( 0, $linkCache->addLinkObj( $existing ) ); // now set the "read latest" flag and try again $flags = IDBAccessObject::READ_LATEST; $this->assertSame( 0, $linkCache->addLinkObj( $missing, $flags ) ); $this->assertSame( $existing->getId(), $linkCache->addLinkObj( $existing, $flags ) ); } /** * @covers \MediaWiki\Cache\LinkCache::addLinkObj() */ public function testAddLinkObjUsesWANCache() { // For some namespaces we cache data (Template, File, etc) $existing = $this->getExistingTestPage( Title::makeTitle( NS_TEMPLATE, __METHOD__ ) ); $wanCache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ); $linkCache = $this->newLinkCache( $wanCache ); // load the page row into the cache $linkCache->addLinkObj( $existing ); // replace real row data with fake, and assert that it gets used $key = $wanCache->makeKey( 'page', $existing->getNamespace(), sha1( $existing->getDBkey() ) ); $fakeRow = $this->getPageRow( $existing->getId() + 100 ); $wanCache->set( $key, $fakeRow ); // clear in-class cache $linkCache->clearLink( $existing ); $this->assertSame( (int)$fakeRow->page_id, $linkCache->addLinkObj( $existing ) ); // set the "read latest" flag and try again $flags = IDBAccessObject::READ_LATEST; $this->assertSame( $existing->getId(), $linkCache->addLinkObj( $existing, $flags ) ); } public function testFalsyPageName() { $linkCache = $this->newLinkCache(); // The stringified value is "0", which is falsy in PHP! $link = new TitleValue( NS_MAIN, '0' ); $linkCache->addBadLinkObj( $link ); $this->assertTrue( $linkCache->isBadLink( $link ) ); $row = $this->getPageRow(); $linkCache->addGoodLinkObjFromRow( $link, $row ); $this->assertGreaterThan( 0, $linkCache->getGoodLinkID( $link ) ); $this->assertSame( $row, $linkCache->getGoodLinkRow( NS_MAIN, '0' ) ); } public function testClearBadLinkWithString() { $linkCache = $this->newLinkCache(); $linkCache->clearBadLink( 'Xyzzy' ); $this->addToAssertionCount( 1 ); } public function testIsBadLinkWithString() { $linkCache = $this->newLinkCache(); $this->assertFalse( $linkCache->isBadLink( 'Xyzzy' ) ); } public function testGetGoodLinkIdWithString() { $linkCache = $this->newLinkCache(); $this->assertSame( 0, $linkCache->getGoodLinkID( 'Xyzzy' ) ); } public static function provideInvalidPageParams() { return [ 'empty' => [ NS_MAIN, '' ], 'bad chars' => [ NS_MAIN, '_|_' ], 'empty in namspace' => [ NS_USER, '' ], 'special' => [ NS_SPECIAL, 'RecentChanges' ], ]; } /** * @dataProvider provideInvalidPageParams * @covers \MediaWiki\Cache\LinkCache::getGoodLinkRow() */ public function testGetGoodLinkRowWithBadParams( $ns, $dbkey ) { $linkCache = $this->newLinkCache(); $this->assertNull( $linkCache->getGoodLinkRow( $ns, $dbkey ) ); } public function getRowIfExisting( $db, $ns, $dbkey, $queryOptions ) { if ( $dbkey === 'Existing' ) { return $this->getPageRow(); } return null; } /** * @covers \MediaWiki\Cache\LinkCache::getGoodLinkRow() * @covers \MediaWiki\Cache\LinkCache::getGoodLinkFieldObj */ public function testGetGoodLinkRow() { $existing = new TitleValue( NS_MAIN, 'Existing' ); $missing = new TitleValue( NS_MAIN, 'Missing' ); $linkCache = $this->newLinkCache(); $callback = [ $this, 'getRowIfExisting' ]; $linkCache->getGoodLinkRow( $existing->getNamespace(), $existing->getDBkey(), $callback ); $linkCache->getGoodLinkRow( $missing->getNamespace(), $missing->getDBkey(), $callback ); $this->assertTrue( $linkCache->isBadLink( $missing ) ); $this->assertFalse( $linkCache->isBadLink( $existing ) ); $this->assertGreaterThan( 0, $linkCache->getGoodLinkID( $existing ) ); $this->assertTrue( $linkCache->isBadLink( $missing ) ); // Make sure nothing explodes when getting a field from a non-existing entry $this->assertNull( $linkCache->getGoodLinkFieldObj( $missing, 'length' ) ); } /** * @covers \MediaWiki\Cache\LinkCache::getGoodLinkRow() */ public function testGetGoodLinkRowUsesCachedInfo() { $existing = new TitleValue( NS_MAIN, 'Existing' ); $missing = new TitleValue( NS_MAIN, 'Missing' ); $callback = [ $this, 'getRowIfExisting' ]; $existingRow = $this->getPageRow( 0 ); $fakeRow = $this->getPageRow( 3 ); $linkCache = $this->newLinkCache(); // pretend the existing page is missing, and the missing page exists $linkCache->addGoodLinkObjFromRow( $missing, $fakeRow ); $linkCache->addBadLinkObj( $existing ); // the LinkCache should use the cached info and not look into the database $this->assertSame( $fakeRow, $linkCache->getGoodLinkRow( $missing->getNamespace(), $missing->getDBkey(), $callback ) ); $this->assertNull( $linkCache->getGoodLinkRow( $existing->getNamespace(), $existing->getDBkey(), $callback ) ); // now set the "read latest" flag and try again $flags = IDBAccessObject::READ_LATEST; $this->assertNull( $linkCache->getGoodLinkRow( $missing->getNamespace(), $missing->getDBkey(), $callback, $flags ) ); $this->assertEquals( $existingRow, $linkCache->getGoodLinkRow( $existing->getNamespace(), $existing->getDBkey(), $callback, $flags ) ); // pretend again that the missing page exists, but pretend even harder $linkCache->addGoodLinkObjFromRow( $missing, $fakeRow, IDBAccessObject::READ_LATEST ); // the LinkCache should use the cached info and not look into the database $this->assertSame( $fakeRow, $linkCache->getGoodLinkRow( $missing->getNamespace(), $missing->getDBkey(), $callback ) ); // now set the "read latest" flag and try again $flags = IDBAccessObject::READ_LATEST; $this->assertEquals( $fakeRow, $linkCache->getGoodLinkRow( $missing->getNamespace(), $missing->getDBkey(), $callback, $flags ) ); } } PK ! � GenderCacheTest.phpnu �Iw�� <?php use MediaWiki\Cache\GenderCache; /** * @group Database * @group Cache */ class GenderCacheTest extends MediaWikiLangTestCase { /** @var string[] User key => username */ private static $nameMap; public function addDBDataOnce() { // ensure the correct default gender $this->mergeMwGlobalArrayValue( 'wgDefaultUserOptions', [ 'gender' => 'unknown' ] ); $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); $male = $this->getMutableTestUser()->getUser(); $userOptionsManager->setOption( $male, 'gender', 'male' ); $male->saveSettings(); $female = $this->getMutableTestUser()->getUser(); $userOptionsManager->setOption( $female, 'gender', 'female' ); $female->saveSettings(); $default = $this->getMutableTestUser()->getUser(); $userOptionsManager->setOption( $default, 'gender', null ); $default->saveSettings(); self::$nameMap = [ 'UTMale' => $male->getName(), 'UTFemale' => $female->getName(), 'UTDefaultGender' => $default->getName() ]; } /** * test usernames * * @dataProvider provideUserGenders * @covers \MediaWiki\Cache\GenderCache::getGenderOf */ public function testUserName( $userKey, $expectedGender ) { $genderCache = $this->getServiceContainer()->getGenderCache(); $username = self::$nameMap[$userKey] ?? $userKey; $gender = $genderCache->getGenderOf( $username ); $this->assertEquals( $expectedGender, $gender, "GenderCache normal" ); } /** * genderCache should work with user objects, too * * @dataProvider provideUserGenders * @covers \MediaWiki\Cache\GenderCache::getGenderOf */ public function testUserObjects( $userKey, $expectedGender ) { $username = self::$nameMap[$userKey] ?? $userKey; $genderCache = $this->getServiceContainer()->getGenderCache(); $gender = $genderCache->getGenderOf( $username ); $this->assertEquals( $expectedGender, $gender, "GenderCache normal" ); } public static function provideUserGenders() { return [ [ 'UTMale', 'male' ], [ 'UTFemale', 'female' ], [ 'UTDefaultGender', 'unknown' ], [ 'UTNotExist', 'unknown' ], // some not valid user [ '127.0.0.1', 'unknown' ], [ 'user@test', 'unknown' ], ]; } /** * test strip of subpages to avoid unnecessary queries * against the never existing username * * @dataProvider provideUserGenders * @covers \MediaWiki\Cache\GenderCache::getGenderOf */ public function testStripSubpages( $userKey, $expectedGender ) { $username = self::$nameMap[$userKey] ?? $userKey; $genderCache = $this->getServiceContainer()->getGenderCache(); $gender = $genderCache->getGenderOf( "$username/subpage" ); $this->assertEquals( $expectedGender, $gender, "GenderCache must strip of subpages" ); } /** * GenderCache must work without database (like Installer) * @coversNothing */ public function testWithoutDB() { $this->overrideMwServices(); $services = $this->getServiceContainer(); $services->disableService( 'DBLoadBalancer' ); $services->disableService( 'DBLoadBalancerFactory' ); // Make sure the disable works $this->assertTrue( $services->isServiceDisabled( 'DBLoadBalancer' ) ); // Test, if it is possible to create the gender cache $genderCache = $services->getGenderCache(); $this->assertInstanceOf( GenderCache::class, $genderCache ); } } PK ! L?�z z BacklinkCacheTest.phpnu �Iw�� <?php use MediaWiki\Title\Title; /** * @group Database * @group Cache * @covers \MediaWiki\Cache\BacklinkCache */ class BacklinkCacheTest extends MediaWikiIntegrationTestCase { /** @var array */ private static $backlinkCacheTest; public function addDBDataOnce() { $this->insertPage( 'Template:BacklinkCacheTestA', 'wooooooo' ); $this->insertPage( 'Template:BacklinkCacheTestB', '{{BacklinkCacheTestA}}' ); self::$backlinkCacheTest = $this->insertPage( 'BacklinkCacheTest_1', '{{BacklinkCacheTestB}}' ); $this->insertPage( 'BacklinkCacheTest_2', '[[BacklinkCacheTest_1]] [[Image:test.png]]' ); $this->insertPage( 'BacklinkCacheTest_3', '[[BacklinkCacheTest_1]]' ); $this->insertPage( 'BacklinkCacheTest_4', '[[BacklinkCacheTest_1]]' ); $this->insertPage( 'BacklinkCacheTest_5', '[[BacklinkCacheTest_1]]' ); $cascade = 1; $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( self::$backlinkCacheTest['title'] )->doUpdateRestrictions( [ 'edit' => 'sysop' ], [], $cascade, 'test', $this->getTestSysop()->getUser() ); } public static function provideCasesForHasLink() { return [ [ true, 'BacklinkCacheTest_1', 'pagelinks' ], [ false, 'BacklinkCacheTest_2', 'pagelinks' ], [ true, 'Image:test.png', 'imagelinks' ] ]; } /** * @dataProvider provideCasesForHasLink * @covers \MediaWiki\Cache\BacklinkCache::hasLinks */ public function testHasLink( bool $expected, string $title, string $table, string $msg = '' ) { $blcFactory = $this->getServiceContainer()->getBacklinkCacheFactory(); $backlinkCache = $blcFactory->getBacklinkCache( Title::newFromText( $title ) ); $this->assertEquals( $expected, $backlinkCache->hasLinks( $table ), $msg ); } public static function provideCasesForGetNumLinks() { return [ [ 4, 'BacklinkCacheTest_1', 'pagelinks' ], [ 0, 'BacklinkCacheTest_2', 'pagelinks' ], [ 1, 'Image:test.png', 'imagelinks' ], ]; } /** * @dataProvider provideCasesForGetNumLinks * @covers \MediaWiki\Cache\BacklinkCache::getNumLinks */ public function testGetNumLinks( int $numLinks, string $title, string $table ) { $blcFactory = $this->getServiceContainer()->getBacklinkCacheFactory(); $backlinkCache = $blcFactory->getBacklinkCache( Title::newFromText( $title ) ); $this->assertEquals( $numLinks, $backlinkCache->getNumLinks( $table ) ); } public static function provideCasesForGetLinks() { return [ [ [ 'BacklinkCacheTest_2', 'BacklinkCacheTest_3', 'BacklinkCacheTest_4', 'BacklinkCacheTest_5' ], 'BacklinkCacheTest_1', 'pagelinks' ], [ [ 'BacklinkCacheTest_4', 'BacklinkCacheTest_5' ], 'BacklinkCacheTest_1', 'pagelinks', 'BacklinkCacheTest_4' ], [ [ 'BacklinkCacheTest_2', 'BacklinkCacheTest_3' ], 'BacklinkCacheTest_1', 'pagelinks', false, 'BacklinkCacheTest_3' ], [ [ 'BacklinkCacheTest_3', 'BacklinkCacheTest_4' ], 'BacklinkCacheTest_1', 'pagelinks', 'BacklinkCacheTest_3', 'BacklinkCacheTest_4' ], [ [ 'BacklinkCacheTest_2' ], 'BacklinkCacheTest_1', 'pagelinks', false, false, 1 ], [ [], 'BacklinkCacheTest_2', 'pagelinks' ], [ [ 'BacklinkCacheTest_2' ], 'Image:test.png', 'imagelinks' ], ]; } /** * @dataProvider provideCasesForGetLinks * @covers \MediaWiki\Cache\BacklinkCache::getLinkPages */ public function testGetLinkPages( array $expectedTitles, string $title, string $table, $startId = false, $endId = false, $max = INF ) { $startId = $startId ? Title::newFromText( $startId )->getId() : false; $endId = $endId ? Title::newFromText( $endId )->getId() : false; $blcFactory = $this->getServiceContainer()->getBacklinkCacheFactory(); $backlinkCache = $blcFactory->getBacklinkCache( Title::newFromText( $title ) ); $titlesArray = iterator_to_array( $backlinkCache->getLinkPages( $table, $startId, $endId, $max ) ); $this->assertSameSize( $expectedTitles, $titlesArray ); $numOfTitles = count( $titlesArray ); for ( $i = 0; $i < $numOfTitles; $i++ ) { $this->assertEquals( $expectedTitles[$i], $titlesArray[$i]->getDbKey() ); } } /** * @covers \MediaWiki\Cache\BacklinkCache::partition */ public function testPartition() { $targetId = $this->getServiceContainer()->getLinkTargetLookup()->acquireLinkTargetId( Title::makeTitle( NS_MAIN, 'BLCTest1234' ), $this->getDb() ); $targetRow = [ 'tl_target_id' => $targetId, ]; $this->getDb()->newInsertQueryBuilder() ->insertInto( 'templatelinks' ) ->rows( [ [ 'tl_from' => 56890, 'tl_from_namespace' => 0 ] + $targetRow, [ 'tl_from' => 56891, 'tl_from_namespace' => 0 ] + $targetRow, [ 'tl_from' => 56892, 'tl_from_namespace' => 0 ] + $targetRow, [ 'tl_from' => 56893, 'tl_from_namespace' => 0 ] + $targetRow, [ 'tl_from' => 56894, 'tl_from_namespace' => 0 ] + $targetRow, ] ) ->caller( __METHOD__ ) ->execute(); $blcFactory = $this->getServiceContainer()->getBacklinkCacheFactory(); $backlinkCache = $blcFactory->getBacklinkCache( Title::makeTitle( NS_MAIN, 'BLCTest1234' ) ); $partition = $backlinkCache->partition( 'templatelinks', 2 ); $this->assertArrayEquals( [ [ false, 56891 ], [ 56892, 56893 ], [ 56894, false ] ], $partition ); } } PK ! vz<| | LinkCacheTestTrait.phpnu �Iw�� <?php use MediaWiki\Linker\LinkTarget; use MediaWiki\MediaWikiServices; use MediaWiki\Page\PageReference; /** * A trait providing utility functions for testing LinkCache. * This trait is intended to be used on subclasses of * MediaWikiIntegrationTestCase. * * @stable to use * @since 1.37 */ trait LinkCacheTestTrait { /** * Force information about a page into the cache, pretending it exists. * * @param int $id Page's ID * @param LinkTarget|PageReference $page The page to set cached info for. * @param int $len Text's length * @param int|null $redir Whether the page is a redirect * @param int $revision Latest revision's ID * @param string|null $model Latest revision's content model ID * @param string|null $lang Language code of the page, if not the content language */ public function addGoodLinkObject( $id, $page, $len = -1, $redir = null, $revision = 0, $model = null, $lang = null ) { MediaWikiServices::getInstance()->getLinkCache()->addGoodLinkObjFromRow( $page, (object)[ 'page_id' => (int)$id, 'page_namespace' => $page->getNamespace(), 'page_title' => $page->getDBkey(), 'page_len' => (int)$len, 'page_is_redirect' => (int)$redir, 'page_latest' => (int)$revision, 'page_content_model' => $model ? (string)$model : null, 'page_lang' => $lang ? (string)$lang : null, 'page_is_new' => 0, 'page_touched' => '', ] ); } } PK ! �� ! ! LinkBatchTest.phpnu �Iw�� <?php use MediaWiki\Cache\CacheKeyHelper; use MediaWiki\Cache\GenderCache; use MediaWiki\Cache\LinkBatch; use MediaWiki\Cache\LinkCache; use MediaWiki\Language\Language; use MediaWiki\Linker\LinksMigration; use MediaWiki\Linker\LinkTarget; use MediaWiki\Logger\LoggerFactory; use MediaWiki\Page\PageReference; use MediaWiki\Page\PageReferenceValue; use MediaWiki\Title\Title; use MediaWiki\Title\TitleFormatter; use MediaWiki\Title\TitleValue; use Wikimedia\Rdbms\IConnectionProvider; /** * @group Database * @group Cache * @covers \MediaWiki\Cache\LinkBatch */ class LinkBatchTest extends MediaWikiIntegrationTestCase { /** * @covers \MediaWiki\Cache\LinkBatch::__construct() * @covers \MediaWiki\Cache\LinkBatch::getSize() * @covers \MediaWiki\Cache\LinkBatch::isEmpty() */ public function testConstructEmptyWithServices() { $batch = new LinkBatch( [], $this->createMock( LinkCache::class ), $this->createMock( TitleFormatter::class ), $this->createMock( Language::class ), $this->createMock( GenderCache::class ), $this->createMock( IConnectionProvider::class ), $this->createMock( LinksMigration::class ), LoggerFactory::getInstance( 'LinkBatch' ) ); $this->assertTrue( $batch->isEmpty() ); $this->assertSame( 0, $batch->getSize() ); } /** * @covers \MediaWiki\Cache\LinkBatch::__construct() * @covers \MediaWiki\Cache\LinkBatch::getSize() * @covers \MediaWiki\Cache\LinkBatch::isEmpty() */ public function testConstructWithServices() { $batch = new LinkBatch( [ new TitleValue( NS_MAIN, 'Foo' ), new TitleValue( NS_TALK, 'Bar' ), ], $this->createMock( LinkCache::class ), $this->createMock( TitleFormatter::class ), $this->createMock( Language::class ), $this->createMock( GenderCache::class ), $this->createMock( IConnectionProvider::class ), $this->createMock( LinksMigration::class ), LoggerFactory::getInstance( 'LinkBatch' ) ); $this->assertFalse( $batch->isEmpty() ); $this->assertSame( 2, $batch->getSize() ); } /** * @param iterable<LinkTarget>|iterable<PageReference> $objects * * @return LinkBatch * @throws Exception */ private function newLinkBatch( $objects = [] ) { return new LinkBatch( $objects, $this->createMock( LinkCache::class ), $this->createMock( TitleFormatter::class ), $this->createMock( Language::class ), $this->createMock( GenderCache::class ), $this->getServiceContainer()->getConnectionProvider(), $this->getServiceContainer()->getLinksMigration(), LoggerFactory::getInstance( 'LinkBatch' ) ); } /** * @covers \MediaWiki\Cache\LinkBatch::addObj() * @covers \MediaWiki\Cache\LinkBatch::getSize() */ public function testAddObj() { $batch = $this->newLinkBatch( [ new TitleValue( NS_MAIN, 'Foo' ), new PageReferenceValue( NS_USER, 'Foo', PageReference::LOCAL ), ] ); $batch->addObj( new PageReferenceValue( NS_TALK, 'Bar', PageReference::LOCAL ) ); $batch->addObj( new TitleValue( NS_MAIN, 'Foo' ) ); $this->assertSame( 3, $batch->getSize() ); $this->assertCount( 3, $batch->getPageIdentities() ); } /** * @covers \MediaWiki\Cache\LinkBatch::add() * @covers \MediaWiki\Cache\LinkBatch::getSize() */ public function testAdd() { $batch = $this->newLinkBatch( [ new TitleValue( NS_MAIN, 'Foo' ) ] ); $batch->add( NS_TALK, 'Bar' ); $batch->add( NS_MAIN, 'Foo' ); $this->assertSame( 2, $batch->getSize() ); $this->assertCount( 2, $batch->getPageIdentities() ); } public function testExecute() { $existing1 = $this->getExistingTestPage( __METHOD__ . '1' )->getTitle(); $existing2 = $this->getExistingTestPage( __METHOD__ . '2' )->getTitle(); $nonexisting1 = $this->getNonexistingTestPage( __METHOD__ . 'x' )->getTitle(); $nonexisting2 = $this->getNonexistingTestPage( __METHOD__ . 'y' )->getTitle(); $cache = $this->createMock( LinkCache::class ); $good = []; $bad = []; $cache->expects( $this->exactly( 2 ) ) ->method( 'addGoodLinkObjFromRow' ) ->willReturnCallback( static function ( TitleValue $title, $row ) use ( &$good ) { $good["$title"] = $title; } ); $cache->expects( $this->exactly( 2 ) ) ->method( 'addBadLinkObj' ) ->willReturnCallback( static function ( TitleValue $title ) use ( &$bad ) { $bad["$title"] = $title; } ); $services = $this->getServiceContainer(); $batch = new LinkBatch( [], $cache, // TODO: This would be even better with mocked dependencies $services->getTitleFormatter(), $services->getContentLanguage(), $services->getGenderCache(), $services->getConnectionProvider(), $services->getLinksMigration(), LoggerFactory::getInstance( 'LinkBatch' ) ); $batch->addObj( $existing1 ); $batch->addObj( $existing2 ); $batch->addObj( $nonexisting1 ); $batch->addObj( $nonexisting2 ); // Bad stuff, should be skipped! $batch->add( NS_MAIN, '_X' ); $batch->add( NS_MAIN, 'X_' ); $batch->add( NS_MAIN, '' ); @$batch->execute(); $this->assertArrayHasKey( $existing1->getTitleValue()->__toString(), $good ); $this->assertArrayHasKey( $existing2->getTitleValue()->__toString(), $good ); $this->assertArrayHasKey( $nonexisting1->getTitleValue()->__toString(), $bad ); $this->assertArrayHasKey( $nonexisting2->getTitleValue()->__toString(), $bad ); $expected = array_map( [ CacheKeyHelper::class, 'getKeyForPage' ], [ $existing1, $existing2, $nonexisting1, $nonexisting2 ] ); $actual = array_map( [ CacheKeyHelper::class, 'getKeyForPage' ], $batch->getPageIdentities() ); sort( $expected ); sort( $actual ); $this->assertEquals( $expected, $actual ); } public function testDoGenderQueryWithEmptyLinkBatch() { $batch = new LinkBatch( [], $this->createMock( LinkCache::class ), $this->createMock( TitleFormatter::class ), $this->createNoOpMock( Language::class ), $this->createNoOpMock( GenderCache::class ), $this->createMock( IConnectionProvider::class ), $this->createMock( LinksMigration::class ), LoggerFactory::getInstance( 'LinkBatch' ) ); $this->assertFalse( $batch->doGenderQuery() ); } public function testDoGenderQueryWithLanguageWithoutGenderDistinction() { $language = $this->createMock( Language::class ); $language->method( 'needsGenderDistinction' )->willReturn( false ); $batch = new LinkBatch( [], $this->createMock( LinkCache::class ), $this->createMock( TitleFormatter::class ), $language, $this->createNoOpMock( GenderCache::class ), $this->createMock( IConnectionProvider::class ), $this->createMock( LinksMigration::class ), LoggerFactory::getInstance( 'LinkBatch' ) ); $batch->addObj( new TitleValue( NS_MAIN, 'Foo' ) ); $this->assertFalse( $batch->doGenderQuery() ); } public function testDoGenderQueryWithLanguageWithGenderDistinction() { $language = $this->createMock( Language::class ); $language->method( 'needsGenderDistinction' )->willReturn( true ); $genderCache = $this->createMock( GenderCache::class ); $genderCache->expects( $this->once() )->method( 'doLinkBatch' ); $batch = new LinkBatch( [], $this->createMock( LinkCache::class ), $this->createMock( TitleFormatter::class ), $language, $genderCache, $this->createMock( IConnectionProvider::class ), $this->createMock( LinksMigration::class ), LoggerFactory::getInstance( 'LinkBatch' ) ); $batch->addObj( new TitleValue( NS_MAIN, 'Foo' ) ); $this->assertTrue( $batch->doGenderQuery() ); } public static function provideBadObjects() { yield 'null' => [ null ]; yield 'empty' => [ Title::makeTitle( NS_MAIN, '' ) ]; yield 'bad user' => [ Title::makeTitle( NS_USER, '#12345' ) ]; yield 'section' => [ new TitleValue( NS_MAIN, '', '#See_also' ) ]; yield 'special' => [ new TitleValue( NS_SPECIAL, 'RecentChanges' ) ]; } /** * @dataProvider provideBadObjects */ public function testAddBadObj( $obj ) { $linkBatch = $this->newLinkBatch(); $linkBatch->addObj( $obj ); $linkBatch->execute(); $this->addToAssertionCount( 1 ); } public static function provideBadDBKeys() { yield 'empty' => [ '' ]; yield 'section' => [ '#See_also' ]; yield 'pipe' => [ 'foo|bar' ]; } /** * @dataProvider provideBadDBKeys */ public function testAddBadDBKeys( $key ) { $linkBatch = $this->newLinkBatch(); $linkBatch->add( NS_MAIN, $key ); $linkBatch->execute(); $this->addToAssertionCount( 1 ); } } PK ! �wɤ�: �: LinkCacheTest.phpnu �Iw�� PK ! � :; GenderCacheTest.phpnu �Iw�� PK ! L?�z z �H BacklinkCacheTest.phpnu �Iw�� PK ! vz<| | B] LinkCacheTestTrait.phpnu �Iw�� PK ! �� ! ! c LinkBatchTest.phpnu �Iw�� PK � E�
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка