blob: 71c129a9de308fb3990054dd7a4408d010ffe414 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php
namespace SMW\Tests\DataValues\ValueParsers;
use SMW\DataValues\ValueParsers\AllowsListValueParser;
/**
* @covers \SMW\DataValues\ValueParsers\AllowsListValueParser
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 2.5
*
* @author mwjames
*/
class AllowsListValueParserTest extends \PHPUnit_Framework_TestCase {
private $mediaWikiNsContentReader;
protected function setUp() {
$this->mediaWikiNsContentReader = $this->getMockBuilder( '\SMW\MediaWiki\MediaWikiNsContentReader' )
->disableOriginalConstructor()
->getMock();
}
public function testCanConstruct() {
$this->assertInstanceOf(
'\SMW\DataValues\ValueParsers\AllowsListValueParser',
new AllowsListValueParser( $this->mediaWikiNsContentReader )
);
}
public function testParseAndMatchFromResource() {
$this->mediaWikiNsContentReader->expects( $this->once() )
->method( 'read' )
->will( $this->returnValue( " \n*Foo\n**Foobar|bar\n" ) );
$instance = new AllowsListValueParser(
$this->mediaWikiNsContentReader
);
$this->assertEquals(
[
'Foo' => 'Foo',
'Foobar' => 'bar'
],
$instance->parse( 'Bar' )
);
}
public function testParseAndMatchFromJSON() {
$contents = json_encode( [ 'Foo' => 'Foo', 'Foobar' => 'fooooo bar' ] );
$this->mediaWikiNsContentReader->expects( $this->once() )
->method( 'read' )
->will( $this->returnValue( $contents ) );
$instance = new AllowsListValueParser(
$this->mediaWikiNsContentReader
);
$instance->clear();
$this->assertEquals(
[
'Foo' => 'Foo',
'Foobar' => 'fooooo bar'
],
$instance->parse( 'Bar' )
);
}
}
|