Completed
Push — master ( 2a8480...b4e0c6 )
by mw
415:39 queued 380:48
created

testNewCompositePropertyTableDiffIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Tests\SQLStore\ChangeOp;
4
5
use SMW\SQLStore\ChangeOp\TempChangeOpStore;
6
use Onoi\MessageReporter\MessageReporterFactory;
7
8
/**
9
 * @covers \SMW\SQLStore\ChangeOp\TempChangeOpStore
10
 * @group semantic-mediawiki
11
 *
12
 * @license GNU GPL v2+
13
 * @since 2.5
14
 *
15
 * @author mwjames
16
 */
17
class TempChangeOpStoreTest extends \PHPUnit_Framework_TestCase {
18
19
	private $cache;
20
	private $compositePropertyTableDiffIterator;
21
22
	protected function setUp() {
23
24
		$this->cache = $this->getMockBuilder( '\Onoi\Cache\Cache' )
25
			->disableOriginalConstructor()
26
			->getMock();
27
28
		$this->compositePropertyTableDiffIterator = $this->getMockBuilder( '\SMW\SQLStore\CompositePropertyTableDiffIterator' )
29
			->disableOriginalConstructor()
30
			->getMock();
31
	}
32
33
	public function testCanConstruct() {
34
35
		$this->assertInstanceOf(
36
			'\SMW\SQLStore\ChangeOp\TempChangeOpStore',
37
			new TempChangeOpStore( $this->cache )
38
		);
39
	}
40
41
	public function testGetSlot() {
42
43
		$instance = new TempChangeOpStore(
44
			$this->cache
45
		);
46
47
		$this->assertContains(
48
			'smw:diff',
49
			$instance->getSlot( $this->compositePropertyTableDiffIterator )
50
		);
51
	}
52
53
	public function testCreateSlotWithDiff() {
54
55
		$this->cache->expects( $this->once() )
56
			->method( 'save' )
57
			->will( $this->returnValue( array() ) );
58
59
		$this->compositePropertyTableDiffIterator->expects( $this->once() )
60
			->method( 'getOrderedDiffByTable' )
61
			->will( $this->returnValue( array( 'Foo' => 'Bar' ) ) );
62
63
		$instance = new TempChangeOpStore(
64
			$this->cache
65
		);
66
67
		$this->assertContains(
68
			'smw:diff',
69
			$instance->createSlotFrom( $this->compositePropertyTableDiffIterator )
70
		);
71
	}
72
73
	public function testCreateSlotWithEmptyDiff() {
74
75
		$this->cache->expects( $this->never() )
76
			->method( 'save' );
77
78
		$this->compositePropertyTableDiffIterator->expects( $this->once() )
79
			->method( 'getOrderedDiffByTable' )
80
			->will( $this->returnValue( array() ) );
81
82
		$instance = new TempChangeOpStore(
83
			$this->cache
84
		);
85
86
		$this->assertNull(
87
			$instance->createSlotFrom( $this->compositePropertyTableDiffIterator )
88
		);
89
	}
90
91
	public function testNewCompositePropertyTableDiffIterator() {
92
93
		$this->cache->expects( $this->once() )
94
			->method( 'fetch' )
95
			->will( $this->returnValue( serialize( $this->compositePropertyTableDiffIterator ) ) );
96
97
		$instance = new TempChangeOpStore(
98
			$this->cache
99
		);
100
101
		$this->assertInstanceOf(
102
			'\SMW\SQLStore\CompositePropertyTableDiffIterator',
103
			$instance->newCompositePropertyTableDiffIterator( 'foo' )
104
		);
105
	}
106
107
	public function testNewCompositePropertyTableDiffIteratorOnInvalidSlot() {
108
109
		$this->cache->expects( $this->once() )
110
			->method( 'fetch' )
111
			->will( $this->returnValue( false ) );
112
113
		$instance = new TempChangeOpStore(
114
			$this->cache
115
		);
116
117
		$this->assertNull(
118
			$instance->newCompositePropertyTableDiffIterator( 'foo' )
119
		);
120
	}
121
122
	public function testDelete() {
123
124
		$this->cache->expects( $this->once() )
125
			->method( 'delete' );
126
127
		$instance = new TempChangeOpStore(
128
			$this->cache
129
		);
130
131
		$instance->delete( 'foo' );
132
	}
133
134
}
135