summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SPARQLStore/ReplicationDataTruncatorTest.php
blob: 4ef8f747c9bebf06fd624adf6f4f348e5c153b73 (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
<?php

namespace SMW\Tests\SPARQLStore;

use SMW\DIProperty;
use SMW\SPARQLStore\ReplicationDataTruncator;

/**
 * @covers \SMW\SPARQLStore\ReplicationDataTruncator
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 2.5
 *
 * @author mwjames
 */
class ReplicationDataTruncatorTest extends \PHPUnit_Framework_TestCase {

	private $semanticData;

	public function setUp() {

		$this->semanticData = $this->getMockBuilder( '\SMW\semanticData' )
			->disableOriginalConstructor()
			->getMock();
	}

	public function testCanConstruct() {

		$this->assertInstanceOf(
			'\SMW\SPARQLStore\ReplicationDataTruncator',
			new ReplicationDataTruncator()
		);
	}

	public function testOnEmptyList() {

		$instance = new ReplicationDataTruncator();
		$semanticData = $instance->doTruncate( $this->semanticData );

		$this->assertSame(
			$this->semanticData,
			$semanticData
		);
	}

	public function testOnExemptedList() {

		$property = new DIProperty( 'Foo_bar' );

		$this->semanticData->expects( $this->once() )
			->method( 'removeProperty' )
			->with( $this->equalTo( $property ) );

		$instance = new ReplicationDataTruncator();
		$instance->setPropertyExemptionList( [ 'Foo bar' ] );

		$instance->doTruncate( $this->semanticData );
	}

	public function testOnExemptedListWithPredefinedProperty() {

		$property = new DIProperty( '_ASK' );

		$this->semanticData->expects( $this->once() )
			->method( 'removeProperty' )
			->with($this->equalTo( $property ) );

		$instance = new ReplicationDataTruncator();
		$instance->setPropertyExemptionList( [ 'Has query' ] );

		$instance->doTruncate( $this->semanticData );
	}

}