Completed
Push — master ( 498457...3132df )
by mw
02:32
created

ScribuntoLuaLibrarySubobjectTest::testSubobject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace SMW\Scribunto\Tests;
4
5
/**
6
 * @covers \SMW\Scribunto\ScribuntoLuaLibrary
7
 * @group semantic-scribunto
8
 *
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author Tobias Oetterer
13
 */
14
class ScribuntoLuaLibrarySubobjectTest extends ScribuntoLuaEngineTestBase {
15
16
	/**
17
	 * Lua test module
18
	 * @var string
19
	 */
20
	protected static $moduleName = self::class;
21
22
	/**
23
	 * ScribuntoLuaEngineTestBase::getTestModules
24
	 */
25
	public function getTestModules() {
26
		return parent::getTestModules() + array(
27
			self::$moduleName => __DIR__ . '/' . 'mw.smw.subobject.tests.lua',
28
		);
29
	}
30
31
	/**
32
	 * Tests method subobject through assertions based upon
33
	 * dataProvider {@see dataProviderSubobjectTest}
34
	 *
35
	 * @dataProvider dataProviderSubobjectTest
36
	 * @param array $arguments arguments passed to function
37
	 * @param mixed $expected expected return value
38
	 */
39
	public function testSubobject( $arguments, $expected ) {
40
		$this->assertEquals(
41
			$expected,
42
			call_user_func_array( array( $this->getScribuntoLuaLibrary(), 'subobject' ), $arguments )
43
		);
44
	}
45
46
	/**
47
	 * Data provider for {@see testSubobject}
48
	 *
49
	 * @see testSubobject
50
	 *
51
	 * @return array
52
	 */
53
	public function dataProviderSubobjectTest()
54
	{
55
		$provider = array(
56
			[
57
				[ [] ],
58
				[ 1 => true ]
59
			],
60
			[
61
				[ null ],
62
				[ 1 => true ]
63
			],
64
			[
65
				[ '' ],
66
				[ 1 => true ]
67
			],
68
			[
69
				[ [ 'has type=page', 'Allows value=test' ] ],
70
				[ 1 => true ]
71
			],
72
			[
73
				[ [ 'has type=test', 'Allows value=test' ] ],
74
				[ array( 1 => false, 'error' => wfMessage('smw_unknowntype')->inLanguage('en')->plain() ) ]
75
			],
76
			[
77
				[ [ 'has type=page', 'Allows value=test','1215623e790d918773db943232068a93b21c9f1419cb85666c6558e87f5b7d47=test' ] ],
78
				[ 1 => true ]
79
			],
80
			[
81
				[ [], '01234567890_testStringAsId' ],
82
				[ 1 => true ]
83
			],
84
			[
85
				[ null, '01234567890_testStringAsId' ],
86
				[ 1 => true ]
87
			],
88
			[
89
				[ '', '01234567890_testStringAsId' ],
90
				[ 1 => true ]
91
			],
92
			[
93
				[ [ 'has type=page', 'Allows value=test' ], '01234567890_testStringAsId' ],
94
				[ 1 => true ]
95
			],
96
			[
97
				[ [ 'has type=test', 'Allows value=test' ], '01234567890_testStringAsId' ],
98
				[ array( 1 => false, 'error' => wfMessage('smw_unknowntype')->inLanguage('en')->plain() ) ]
99
			],
100
			[
101
				[ [ 'has type=page', 'Allows value' => 'test','1215623e790d918773db943232068a93b21c9f1419cb85666c6558e87f5b7d47=test' ], '01234567890_testStringAsId' ],
102
				[ 1 => true ]
103
			],
104
		);
105
106
		return $provider;
107
	}
108
}