Completed
Push — master ( bb3081...b26d3d )
by mw
9s
created

testNoUpdateOnSameLanguageCode()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 29
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
namespace SIL\Tests;
4
5
use SIL\PageContentLanguageDbModifier;
6
use Title;
7
8
/**
9
 * @covers \SIL\PageContentLanguageDbModifier
10
 * @group semantic-interlanguage-links
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.3
14
 *
15
 * @author mwjames
16
 */
17
class PageContentLanguageDbModifierTest extends \PHPUnit_Framework_TestCase {
18
19
	public function testCanConstruct() {
20
21
		$title = $this->getMockBuilder( '\Title' )
22
			->disableOriginalConstructor()
23
			->getMock();
24
25
		$this->assertInstanceOf(
26
			'\SIL\PageContentLanguageDbModifier',
27
			new PageContentLanguageDbModifier( $title )
28
		);
29
	}
30
31
	public function testNotMarkedAsPageLanguageByDB() {
32
33
		$title = Title::newFromText( __METHOD__ );
34
35
		$connection = $this->getMockBuilder( '\DatabaseBase' )
36
			->disableOriginalConstructor()
37
			->getMockForAbstractClass();
38
39
		$instance = new PageContentLanguageDbModifier(
40
			$title,
41
			$connection
42
		);
43
44
		$instance->markAsPageLanguageByDB( false );
45
46
		$this->assertNull(
47
			$instance->updatePageLanguage( 'en' )
48
		);
49
	}
50
51
	public function testForceUpdateOfPageLanguageOnDifferentLanguageCode() {
52
53
		$title = Title::newFromText( __METHOD__ );
54
55
		$connection = $this->getMockBuilder( '\DatabaseBase' )
56
			->disableOriginalConstructor()
57
			->setMethods( array( 'update' ) )
58
			->getMockForAbstractClass();
59
60
		$connection->expects( $this->once() )
61
			->method( 'update' );
62
63
		$linkCache = $this->getMockBuilder( '\LinkCache' )
64
			->disableOriginalConstructor()
65
			->getMock();
66
67
		$linkCache->expects( $this->once() )
68
			->method( 'getGoodLinkFieldObj' )
69
			->will( $this->returnValue(  'fr' ) );
70
71
		$instance = new PageContentLanguageDbModifier(
72
			$title,
73
			$connection,
74
			$linkCache
75
		);
76
77
		$instance->markAsPageLanguageByDB( true );
78
		$instance->updatePageLanguage( 'en' );
79
	}
80
81
	public function testNoUpdateOnSameLanguageCode() {
82
83
		$title = Title::newFromText( __METHOD__ );
84
85
		$connection = $this->getMockBuilder( '\DatabaseBase' )
86
			->disableOriginalConstructor()
87
			->setMethods( array( 'update' ) )
88
			->getMockForAbstractClass();
89
90
		$connection->expects( $this->never() )
91
			->method( 'update' );
92
93
		$linkCache = $this->getMockBuilder( '\LinkCache' )
94
			->disableOriginalConstructor()
95
			->getMock();
96
97
		$linkCache->expects( $this->once() )
98
			->method( 'getGoodLinkFieldObj' )
99
			->will( $this->returnValue(  'en' ) );
100
101
		$instance = new PageContentLanguageDbModifier(
102
			$title,
103
			$connection,
104
			$linkCache
105
		);
106
107
		$instance->markAsPageLanguageByDB( true );
108
		$instance->updatePageLanguage( 'en' );
109
	}
110
111
}
112