1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SWL\Tests\MediaWiki\Hooks; |
4
|
|
|
|
5
|
|
|
use SWL\MediaWiki\Hooks\ExtensionSchemaUpdater; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SWL\MediaWiki\Hooks\ExtensionSchemaUpdater |
9
|
|
|
* |
10
|
|
|
* @ingroup Test |
11
|
|
|
* |
12
|
|
|
* @group SWL |
13
|
|
|
* @group SWLExtension |
14
|
|
|
* |
15
|
|
|
* @license GNU GPL v2+ |
16
|
|
|
* @since 1.0 |
17
|
|
|
* |
18
|
|
|
* @author mwjames |
19
|
|
|
*/ |
20
|
|
|
class ExtensionSchemaUpdaterTest extends \PHPUnit_Framework_TestCase { |
21
|
|
|
|
22
|
|
|
public function testCanConstruct() { |
23
|
|
|
|
24
|
|
|
$databaseUpdater = $this->getMockBuilder( 'DatabaseUpdater' ) |
25
|
|
|
->disableOriginalConstructor() |
26
|
|
|
->getMockForAbstractClass(); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf( |
29
|
|
|
'\SWL\MediaWiki\Hooks\ExtensionSchemaUpdater', |
30
|
|
|
new ExtensionSchemaUpdater( $databaseUpdater ) |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testNoExtensionUpdateForInvalidDBType() { |
35
|
|
|
|
36
|
|
|
$dbConnection = $this->getMockBuilder( 'DatabaseBase' ) |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMockForAbstractClass(); |
39
|
|
|
|
40
|
|
|
$dbConnection->expects( $this->once() ) |
41
|
|
|
->method( 'getType' ) |
42
|
|
|
->will( $this->returnValue( 'foo' ) ); |
43
|
|
|
|
44
|
|
|
$databaseUpdater = $this->getMockBuilder( 'DatabaseUpdater' ) |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->setMethods( array( |
47
|
|
|
'getDB', |
48
|
|
|
'addExtensionUpdate' ) ) |
49
|
|
|
->getMockForAbstractClass(); |
50
|
|
|
|
51
|
|
|
$databaseUpdater->expects( $this->once() ) |
52
|
|
|
->method( 'getDB' ) |
53
|
|
|
->will( $this->returnValue( $dbConnection ) ); |
54
|
|
|
|
55
|
|
|
$databaseUpdater->expects( $this->never() ) |
56
|
|
|
->method( 'addExtensionUpdate' ) |
57
|
|
|
->will( $this->returnValue( true ) ); |
58
|
|
|
|
59
|
|
|
$instance = new ExtensionSchemaUpdater( $databaseUpdater ); |
60
|
|
|
|
61
|
|
|
$this->assertTrue( $instance->execute() ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @dataProvider dbTypeProvider |
66
|
|
|
*/ |
67
|
|
|
public function testExtensionUpdateForValidDBType( $dbType ) { |
68
|
|
|
|
69
|
|
|
$dbConnection = $this->getMockBuilder( 'DatabaseBase' ) |
70
|
|
|
->disableOriginalConstructor() |
71
|
|
|
->getMockForAbstractClass(); |
72
|
|
|
|
73
|
|
|
$dbConnection->expects( $this->once() ) |
74
|
|
|
->method( 'getType' ) |
75
|
|
|
->will( $this->returnValue( $dbType ) ); |
76
|
|
|
|
77
|
|
|
$databaseUpdater = $this->getMockBuilder( 'DatabaseUpdater' ) |
78
|
|
|
->disableOriginalConstructor() |
79
|
|
|
->setMethods( array( |
80
|
|
|
'getDB', |
81
|
|
|
'addExtensionUpdate' ) ) |
82
|
|
|
->getMockForAbstractClass(); |
83
|
|
|
|
84
|
|
|
$databaseUpdater->expects( $this->once() ) |
85
|
|
|
->method( 'getDB' ) |
86
|
|
|
->will( $this->returnValue( $dbConnection ) ); |
87
|
|
|
|
88
|
|
|
$databaseUpdater->expects( $this->at( 6 ) ) |
89
|
|
|
->method( 'addExtensionUpdate' ) |
90
|
|
|
->will( $this->returnValue( true ) ); |
91
|
|
|
|
92
|
|
|
$configuration = array( 'egSwlSqlDatabaseSchemaPath' => 'foo' ); |
93
|
|
|
|
94
|
|
|
$instance = new ExtensionSchemaUpdater( $databaseUpdater ); |
95
|
|
|
$instance->setConfiguration( $configuration ); |
96
|
|
|
|
97
|
|
|
$this->assertTrue( $instance->execute() ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function dbTypeProvider() { |
101
|
|
|
|
102
|
|
|
$provider = array( |
103
|
|
|
array( 'sqlite' ), |
104
|
|
|
array( 'mysql' ) |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
return $provider; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|