summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/UploadWizard/tests/phpunit/UploadWizardConfigTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/UploadWizard/tests/phpunit/UploadWizardConfigTest.php')
-rw-r--r--www/wiki/extensions/UploadWizard/tests/phpunit/UploadWizardConfigTest.php101
1 files changed, 101 insertions, 0 deletions
diff --git a/www/wiki/extensions/UploadWizard/tests/phpunit/UploadWizardConfigTest.php b/www/wiki/extensions/UploadWizard/tests/phpunit/UploadWizardConfigTest.php
new file mode 100644
index 00000000..46901718
--- /dev/null
+++ b/www/wiki/extensions/UploadWizard/tests/phpunit/UploadWizardConfigTest.php
@@ -0,0 +1,101 @@
+<?php
+
+/**
+ * Test the Upload Wizard Configuration
+ * @group Upload
+ * @covers UploadWizardConfig
+ */
+class UploadWizardConfigTest extends MediaWikiTestCase {
+ public function setUp() {
+ parent::setUp();
+
+ // insert a interwiki prefixes for testing inter-language links.
+ // This is based on ParserTestRunner::setupInterwikis, which does
+ // exactly the same (but with more prefixes) for parser tests.
+ Hooks::register( 'InterwikiLoadPrefix', function ( $prefix, &$iwData ) {
+ static $testInterwikis = [
+ 'es' => [
+ 'iw_url' => 'http://es.wikipedia.org/wiki/$1',
+ 'iw_api' => '',
+ 'iw_wikiid' => '',
+ 'iw_local' => 1 ],
+ ];
+ if ( array_key_exists( $prefix, $testInterwikis ) ) {
+ $iwData = $testInterwikis[$prefix];
+ }
+
+ // We only want to rely on the above fixtures
+ return false;
+ } );
+ }
+
+ public function tearDown() {
+ parent::tearDown();
+
+ Hooks::clear( 'InterwikiLoadPrefix' );
+ }
+
+ public function objRefProvider() {
+ return [
+ [
+ '',
+ false
+ ],
+ [
+ 'JustSomeString',
+ false
+ ],
+ [
+ 'notawiki|Page Title',
+ false
+ ],
+ [
+ 'es|Page Title',
+ 'http://es.wikipedia.org/wiki/Page Title'
+ ],
+ [
+ 'es|Page Title|id12345',
+ 'http://es.wikipedia.org/wiki/Page Title'
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider objRefProvider
+ */
+ public function testButtonTargetIsSetToUseObjRef_buttonHrefMatchesRefPage(
+ $objRef, $expectedResult
+ ) {
+ global $wgUploadWizardConfig;
+
+ $this->setMwGlobals( [
+ 'wgUploadWizardConfig' => array_merge( $wgUploadWizardConfig, [
+ 'defaults' => [ 'objref' => $objRef ],
+ ] ),
+ ] );
+
+ $this->assertEquals(
+ $expectedResult,
+ $this->getHomeButtonHref()
+ );
+ }
+
+ private function getHomeButtonHref() {
+ $campaign = new UploadWizardCampaign( Title::newFromText( 'uw-test-campaign', NS_CAMPAIGN ),
+ [
+ 'enabled' => true,
+ 'display' => [
+ 'homeButton' => [
+ 'label' => 'Back to that list page',
+ 'target' => 'useObjref'
+ ]
+ ]
+ ]
+ );
+
+ $config = $campaign->getParsedConfig();
+ return isset(
+ $config['display']['homeButton']['target']
+ ) ? $config['display']['homeButton']['target'] : false;
+ }
+}