Passed
Push — testing ( 5c3fd5...931c5b )
by Stephan
04:12
created

SimpleBatchUploadTest::assertEarlyConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 21
rs 9.9332
c 1
b 0
f 0
1
<?php
2
/**
3
 * File containing the SimpleBatchUploadTest class
4
 *
5
 * @copyright (C) 2016 - 2019, Stephan Gambke
6
 * @license   GNU General Public License, version 2 (or any later version)
7
 *
8
 * This software is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * This software is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * @file
20
 * @ingroup SimpleBatchUpload
21
 */
22
23
use SimpleBatchUpload\SimpleBatchUpload;
24
25
/**
26
 * @covers \SimpleBatchUpload\SimpleBatchUpload
27
 * @group SimpleBatchUpload
28
 *
29
 * @since 1.5
30
 */
31
class SimpleBatchUploadTest extends PHPUnit_Framework_TestCase {
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
33
	public function testCanConstruct() {
34
35
		$this->assertInstanceOf(
36
			'\SimpleBatchUpload\SimpleBatchUpload',
37
			new SimpleBatchUpload()
38
		);
39
	}
40
41
	public function testRegistersGlobals() {
42
		$this->assertJsonConfiguration( $GLOBALS );
43
		$this->assertEarlyConfiguration( $GLOBALS );
44
		$this->assertLateConfiguration( $GLOBALS );
45
	}
46
47
	public function testRegisterEarlyConfiguraion() {
48
		$sbu = new SimpleBatchUpload();
49
		$config = [];
50
51
		$sbu->registerEarlyConfiguration( $config );
52
		$this->assertEarlyConfiguration( $config );
53
	}
54
55
	public function testRegisterLateConfiguraion() {
56
		$sbu = new SimpleBatchUpload();
57
		$config = [];
58
59
		$sbu->registerLateConfiguration( $config );
60
		$this->assertLateConfiguration( $config );
61
	}
62
63
	public function testRegisterParserFunction() {
64
65
		$parser = $this->getMockBuilder( Parser::class )
0 ignored issues
show
Bug introduced by
The type Parser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
66
			->disableOriginalConstructor()
67
			->getMock();
68
69
		$parser->expects( $this->once() )
70
			->method( 'setFunctionHook' )
71
			->with(
72
				$this->equalTo( 'batchupload' ),
73
				$this->callback( function ( $param ) {
74
					return is_callable( $param );
75
				} ),
76
				$this->equalTo( Parser::SFH_OBJECT_ARGS ) )
77
			->willReturn( null );
78
79
		$sbu = new SimpleBatchUpload();
80
		$sbu->registerParserFunction( $parser );
81
	}
82
83
	public function testOnMakeGlobalVariablesScript() {
84
		$vars = [];
85
		$out = $this->getMockBuilder( OutputPage::class )
0 ignored issues
show
Bug introduced by
The type OutputPage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
86
			->disableOriginalConstructor()
87
			->getMock();
88
89
		$sbu = new SimpleBatchUpload();
90
		$sbu->onMakeGlobalVariablesScript( $vars, $out );
91
92
		$this->assertArrayHasKey( 'simpleBatchUploadMaxFilesPerBatch', $vars );
93
	}
94
95
	/**
96
	 * @param $configuration
97
	 */
98
	public function assertJsonConfiguration( $configuration ) {
99
		$this->assertArrayHasKey( 'wgSimpleBatchUploadMaxFilesPerBatch', $configuration );
100
	}
101
102
		/**
103
	 * @param $configuration
104
	 */
105
	public function assertEarlyConfiguration( $configuration ) {
106
107
		//$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php';
108
		//$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadMagic' ] = __DIR__ . '/SimpleBatchUpload.magic.php';
109
		$this->assertArrayHasKey( 'wgExtensionMessagesFiles', $configuration );
110
		$this->assertArrayHasKey( 'SimpleBatchUploadAlias', $configuration[ 'wgExtensionMessagesFiles' ] );
111
		$this->assertArrayHasKey( 'SimpleBatchUploadMagic', $configuration[ 'wgExtensionMessagesFiles' ] );
112
113
		//$configuration[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload';
114
		$this->assertArrayHasKey( 'wgSpecialPages', $configuration );
115
		$this->assertArrayHasKey( 'BatchUpload', $configuration[ 'wgSpecialPages' ] );
116
117
		//$configuration[ 'wgHooks' ][ 'ParserFirstCallInit' ][ 'ext.simplebatchupload' ] = [ $this, 'registerParserFunction' ];
118
		//$configuration[ 'wgHooks' ][ 'MakeGlobalVariablesScript' ][ 'ext.simplebatchupload' ] = [ $this, 'onMakeGlobalVariablesScript' ];
119
		//$configuration[ 'wgHooks' ][ 'SetupAfterCache' ][ 'ext.simplebatchupload' ] = [ $this, 'onSetupAfterCache'];
120
		$this->assertArrayHasKey( 'wgHooks', $configuration );
121
122
		foreach ( [ 'ParserFirstCallInit', 'MakeGlobalVariablesScript', 'SetupAfterCache' ] as $hook ) {
123
			$this->assertArrayHasKey( $hook, $configuration[ 'wgHooks' ] );
124
			$this->assertArrayHasKey( 'ext.simplebatchupload', $configuration[ 'wgHooks' ][ $hook ] );
125
			$this->assertTrue( is_callable( $configuration[ 'wgHooks' ][ $hook ][ 'ext.simplebatchupload' ] ) );
126
		}
127
	}
128
129
	/**
130
	 * @param $configuration
131
	 */
132
	public function assertLateConfiguration( $configuration ) {
133
134
		$this->assertArrayHasKey( 'wgResourceModules', $configuration );
135
136
		$this->assertArrayHasKey( 'ext.SimpleBatchUpload.jquery-file-upload', $configuration[ 'wgResourceModules' ] );
137
		$this->assertTrue( $configuration[ 'wgResourceModules' ][ 'ext.SimpleBatchUpload.jquery-file-upload' ] === [
138
				'localBasePath'  => dirname( dirname( __DIR__ ) ),
139
				'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload',
140
				'scripts'        => [ 'res/jquery.fileupload.js' ],
141
				'styles'         => [ 'res/jquery.fileupload.css' ],
142
				'position'       => 'top',
143
				'dependencies'   => [ 'jquery.ui.widget' ],
144
			] );
145
146
		$dependencies = [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title', 'mediawiki.jqueryMsg' ];
147
148
		if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.32.0', '>' ) ) {
149
			$dependencies[] = 'mediawiki.api';
150
		} else {
151
			$dependencies[] = 'mediawiki.api.edit';
152
		}
153
154
		$this->assertArrayHasKey( 'ext.SimpleBatchUpload', $configuration[ 'wgResourceModules' ] );
155
		$this->assertTrue( $configuration[ 'wgResourceModules' ][ 'ext.SimpleBatchUpload' ] === [
156
				'localBasePath'  => dirname( dirname( __DIR__ ) ),
157
				'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload',
158
				'scripts'        => [ 'res/ext.SimpleBatchUpload.js' ],
159
				'styles'         => [ 'res/ext.SimpleBatchUpload.css' ],
160
				'position'       => 'top',
161
				'dependencies'   => $dependencies,
162
				'messages'       => [ 'simplebatchupload-comment', 'simplebatchupload-max-files-alert' ],
163
		]);
164
165
	}
166
167
}