summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Search/Form/FormsFinderTest.php
blob: 697c42bace76caa45e791e3fb910f8bddee5a9cb (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
<?php

namespace SMW\Tests\MediaWiki\Search\Form;

use SMW\DIWikiPage;
use SMW\MediaWiki\Search\Form\FormsFinder;

/**
 * @covers \SMW\MediaWiki\Search\Form\FormsFinder
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class FormsFinderTest extends \PHPUnit_Framework_TestCase {

	private $store;

	protected function setUp() {

		$this->store = $this->getMockBuilder( '\SMW\Store' )
			->disableOriginalConstructor()
			->getMockForAbstractClass();
	}

	public function testCanConstruct() {

		$this->assertInstanceOf(
			FormsFinder::class,
			new FormsFinder( $this->store )
		);
	}

	public function testGetFormDefinitions() {

		$data[] = json_encode( [ 'Foo' => [ 'Bar' => 42 ], 1001 ] );
		$data[] = json_encode( [ 'Foo' => [ 'Foobar' => 'test' ], [ 'Foo' => 'Bar' ] ] );

		$this->store->expects( $this->any() )
			->method( 'getPropertySubjects' )
			->will( $this->returnValue( [
				DIWikiPage::newFromText( 'Foo' ),
				DIWikiPage::newFromText( 'Bar' ) ] ) );

		$instance = $this->getMockBuilder( '\SMW\MediaWiki\Search\Form\FormsFinder' )
			->setConstructorArgs( [ $this->store ] )
			->setMethods( [ 'getNativeData' ] )
			->getMock();

		$instance->expects( $this->any() )
			->method( 'getNativeData' )
			->will( $this->onConsecutiveCalls( $data[0], $data[1] ) );

		$this->assertEquals(
			[
				'Foo' => [ 'Bar' => 42, 'Foobar' => 'test' ],
				1001,
				[ 'Foo' => 'Bar' ]
			],
			$instance->getFormDefinitions()
		);
	}

}