diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/Validator/tests |
first commit
Diffstat (limited to 'www/wiki/extensions/Validator/tests')
5 files changed, 238 insertions, 0 deletions
diff --git a/www/wiki/extensions/Validator/tests/bootstrap.php b/www/wiki/extensions/Validator/tests/bootstrap.php new file mode 100644 index 00000000..55d8f80e --- /dev/null +++ b/www/wiki/extensions/Validator/tests/bootstrap.php @@ -0,0 +1,24 @@ +<?php + +if ( php_sapi_name() !== 'cli' ) { + die( 'Not an entry point' ); +} + +$pwd = getcwd(); +chdir( __DIR__ . '/..' ); +passthru( 'composer update' ); +chdir( $pwd ); + +$shouldUseMwHack = !defined( 'MEDIAWIKI' ); + +if ( $shouldUseMwHack ) { + require_once( __DIR__ . '/evilMediaWikiBootstrap.php' ); +} + +require_once( __DIR__ . '/../vendor/autoload.php' ); + +if ( $shouldUseMwHack ) { + foreach ( $GLOBALS['wgExtensionFunctions'] as $extensionFunction ) { + call_user_func( $extensionFunction ); + } +}
\ No newline at end of file diff --git a/www/wiki/extensions/Validator/tests/evilMediaWikiBootstrap.php b/www/wiki/extensions/Validator/tests/evilMediaWikiBootstrap.php new file mode 100644 index 00000000..776a6c14 --- /dev/null +++ b/www/wiki/extensions/Validator/tests/evilMediaWikiBootstrap.php @@ -0,0 +1,72 @@ +<?php + +define( 'MEDIAWIKI', true ); + +global $IP; +$IP = getenv( 'MW_INSTALL_PATH' ); + +if ( $IP === false ) { + $IP = dirname( __FILE__ ) . '/../../..'; +} + +$self = 'foobar'; + +// Detect compiled mode +# Get the MWInit class +require_once "$IP/includes/Init.php"; +require_once "$IP/includes/AutoLoader.php"; +# Stub the profiler +require_once "$IP/includes/profiler/Profiler.php"; + +# Start the profiler +$wgProfiler = array(); +if ( file_exists( "$IP/StartProfiler.php" ) ) { + require "$IP/StartProfiler.php"; +} + +// Some other requires +require_once "$IP/includes/Defines.php"; + +require_once MWInit::compiledPath( 'includes/DefaultSettings.php' ); + +foreach ( get_defined_vars() as $key => $var ) { + if ( !array_key_exists( $key, $GLOBALS ) ) { + $GLOBALS[$key] = $var; + } +} + +if ( defined( 'MW_CONFIG_CALLBACK' ) ) { + # Use a callback function to configure MediaWiki + MWFunction::call( MW_CONFIG_CALLBACK ); +} else { + // Require the configuration (probably LocalSettings.php) + require loadSettings(); +} + +// Some last includes +require_once MWInit::compiledPath( 'includes/Setup.php' ); + +// Much much faster startup than creating a title object +$wgTitle = null; + +global $wgAutoloadClasses; + +if ( is_null( $wgAutoloadClasses ) ) { + $wgAutoloadClasses = array(); +} + +require_once $IP . '/tests/TestsAutoLoader.php'; + +function loadSettings() { + global $wgCommandLineMode, $IP; + + $settingsFile = "$IP/LocalSettings.php"; + + if ( !is_readable( $settingsFile ) ) { + $this->error( "A copy of your installation's LocalSettings.php\n" . + "must exist and be readable in the source directory.\n" . + "Use --conf to specify it.", true ); + } + $wgCommandLineMode = true; + return $settingsFile; +} diff --git a/www/wiki/extensions/Validator/tests/phpunit/Definitions/TitleParamTest.php b/www/wiki/extensions/Validator/tests/phpunit/Definitions/TitleParamTest.php new file mode 100644 index 00000000..eab6a3fe --- /dev/null +++ b/www/wiki/extensions/Validator/tests/phpunit/Definitions/TitleParamTest.php @@ -0,0 +1,77 @@ +<?php + +namespace ParamProcessor\Tests\Definitions; + +/** + * @group Validator + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class TitleParamTest extends ParamDefinitionTest { + + /** + * @see ParamDefinitionTest::getDefinitions + */ + public function getDefinitions() { + $params = parent::getDefinitions(); + + $params['empty-empty'] = $params['empty']; + $params['empty-empty']['hastoexist'] = false; + + $params['values-empty'] = $params['values']; + $params['values-empty']['hastoexist'] = false; + $params['values-empty']['values'][] = \Title::newFromText( 'foo' ); + + return $params; + } + + /** + * @see ParamDefinitionTest::valueProvider + * + * @param boolean $stringlyTyped + * + * @return array + */ + public function valueProvider( $stringlyTyped = true ) { + $values = array( + 'empty-empty' => array( + array( 'foo bar page', true, \Title::newFromText( 'foo bar page' ) ), + array( '|', false ), + array( '', false ), + ), + 'empty' => array( + array( 'foo bar page', false ), + array( '|', false ), + array( '', false ), + ), + 'values-empty' => array( + array( 'foo', true, \Title::newFromText( 'foo' ) ), + array( 'foo bar page', false ), + ), + 'values' => array( + array( 'foo', false ), + array( 'foo bar page', false ), + ), + ); + + if ( !$stringlyTyped ) { + foreach ( $values as &$set ) { + foreach ( $set as &$value ) { + $value[0] = \Title::newFromText( $value[0] ); + } + } + } + + return $values; + } + + /** + * @see ParamDefinitionTest::getType + * @return string + */ + public function getType() { + return 'title'; + } + +} diff --git a/www/wiki/extensions/Validator/tests/phpunit/MediaWikiTitleValueTest.php b/www/wiki/extensions/Validator/tests/phpunit/MediaWikiTitleValueTest.php new file mode 100644 index 00000000..3545b788 --- /dev/null +++ b/www/wiki/extensions/Validator/tests/phpunit/MediaWikiTitleValueTest.php @@ -0,0 +1,22 @@ +<?php + +namespace ParamProcessor\Tests; + +use ParamProcessor\MediaWikiTitleValue; + +/** + * @covers ParamProcessor\MediaWikiTitleValue + * + * @group Validator + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class MediaWikiTitleValueTest extends \PHPUnit_Framework_TestCase { + + public function testGivenValidPage_getValueWorks( ) { + $titleValue = new MediaWikiTitleValue( \Title::newFromText( 'Foobar' ) ); + $this->assertSame( 'Foobar', $titleValue->getValue()->getFullText() ); + } + +} diff --git a/www/wiki/extensions/Validator/tests/phpunit/TitleParserTest.php b/www/wiki/extensions/Validator/tests/phpunit/TitleParserTest.php new file mode 100644 index 00000000..18194c9e --- /dev/null +++ b/www/wiki/extensions/Validator/tests/phpunit/TitleParserTest.php @@ -0,0 +1,43 @@ +<?php + +namespace ParamProcessor\Tests; + +use ParamProcessor\MediaWikiTitleValue; +use ParamProcessor\TitleParser; + +/** + * @group Validator + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroendedauw@gmail.com > + */ +class TitleParserTest extends \PHPUnit_Framework_TestCase { + + /** + * @dataProvider validInputProvider + */ + public function testValidInputs( $input, $expected ) { + $parser = new TitleParser(); + + $this->assertEquals( + $expected, + $parser->parse( $input ) + ); + } + + public function validInputProvider() { + $argLists = array(); + + $valid = array( + 'Foo bar', + 'Ohi there!', + ); + + foreach ( $valid as $value ) { + $argLists[] = array( $value, new MediaWikiTitleValue( \Title::newFromText( $value ) ) ); + } + + return $argLists; + } + +}
\ No newline at end of file |