1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SWL\Tests; |
4
|
|
|
|
5
|
|
|
use SWL\TableUpdater; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SWL\TableUpdater |
9
|
|
|
* |
10
|
|
|
* @group semantic-watchlist |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class TableUpdaterTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
public function setUp() { |
20
|
|
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.28', 'gt' ) ) { |
21
|
|
|
$this->markTestSkipped( |
22
|
|
|
'Test broken on MW > 1.27, see https://github.com/SemanticMediaWiki/SemanticWatchlist/issues/71' |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testCanConstruct() { |
28
|
|
|
|
29
|
|
|
$connectionProvider = $this->getMockBuilder( '\SWL\LazyDBConnectionProvider' ) |
30
|
|
|
->disableOriginalConstructor() |
31
|
|
|
->getMock(); |
32
|
|
|
|
33
|
|
|
$this->assertInstanceOf( |
34
|
|
|
'\SWL\TableUpdater', |
35
|
|
|
new TableUpdater( $connectionProvider ) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testUpdateGroupIdsForUserToReplaceDatasetByUserId() { |
40
|
|
|
|
41
|
|
|
$userId = 1111; |
42
|
|
|
$groupIds = array( 1, 9999 ); |
43
|
|
|
|
44
|
|
|
$connection = $this->getMockBuilder( 'DatabaseBase' ) |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->setMethods( array( 'isOpen', 'delete', 'insert' ) ) |
47
|
|
|
->getMockForAbstractClass(); |
48
|
|
|
|
49
|
|
|
$connection->expects( $this->once() ) |
50
|
|
|
->method( 'delete' ) |
51
|
|
|
->with( |
52
|
|
|
$this->equalTo( 'swl_users_per_group' ), |
53
|
|
|
$this->equalTo( array( 'upg_user_id' => $userId ) ) ); |
54
|
|
|
|
55
|
|
|
$connection->expects( $this->any() ) |
56
|
|
|
->method( 'isOpen' ) |
57
|
|
|
->will( $this->returnValue( true ) ); |
58
|
|
|
|
59
|
|
|
$connection->expects( $this->at( 2 ) ) |
60
|
|
|
->method( 'insert' ) |
61
|
|
|
->will( $this->returnValue( true ) ); |
62
|
|
|
|
63
|
|
|
$connectionProvider = $this->getMockBuilder( '\SWL\LazyDBConnectionProvider' ) |
64
|
|
|
->disableOriginalConstructor() |
65
|
|
|
->getMock(); |
66
|
|
|
|
67
|
|
|
$connectionProvider->expects( $this->any() ) |
68
|
|
|
->method( 'getConnection' ) |
69
|
|
|
->will( $this->returnValue( $connection ) ); |
70
|
|
|
|
71
|
|
|
$instance = new TableUpdater( $connectionProvider ); |
72
|
|
|
|
73
|
|
|
$this->assertTrue( |
74
|
|
|
$instance->updateGroupIdsForUser( $userId, $groupIds ) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testUpdateGroupIdsForUserToOnlyDeleteDatasetByUserId() { |
79
|
|
|
|
80
|
|
|
$userId = 1111; |
81
|
|
|
$groupIds = array(); |
82
|
|
|
|
83
|
|
|
$connection = $this->getMockBuilder( 'DatabaseBase' ) |
84
|
|
|
->disableOriginalConstructor() |
85
|
|
|
->setMethods( array( 'isOpen', 'delete', 'insert' ) ) |
86
|
|
|
->getMockForAbstractClass(); |
87
|
|
|
|
88
|
|
|
$connection->expects( $this->once() ) |
89
|
|
|
->method( 'delete' ) |
90
|
|
|
->with( |
91
|
|
|
$this->equalTo( 'swl_users_per_group' ), |
92
|
|
|
$this->equalTo( array( 'upg_user_id' => $userId ) ) ); |
93
|
|
|
|
94
|
|
|
$connection->expects( $this->any() ) |
95
|
|
|
->method( 'isOpen' ) |
96
|
|
|
->will( $this->returnValue( true ) ); |
97
|
|
|
|
98
|
|
|
$connection->expects( $this->never() ) |
99
|
|
|
->method( 'insert' ) |
100
|
|
|
->will( $this->returnValue( true ) ); |
101
|
|
|
|
102
|
|
|
$connectionProvider = $this->getMockBuilder( '\SWL\LazyDBConnectionProvider' ) |
103
|
|
|
->disableOriginalConstructor() |
104
|
|
|
->getMock(); |
105
|
|
|
|
106
|
|
|
$connectionProvider->expects( $this->any() ) |
107
|
|
|
->method( 'getConnection' ) |
108
|
|
|
->will( $this->returnValue( $connection ) ); |
109
|
|
|
|
110
|
|
|
$instance = new TableUpdater( $connectionProvider ); |
111
|
|
|
|
112
|
|
|
$this->assertTrue( |
113
|
|
|
$instance->updateGroupIdsForUser( $userId, $groupIds ) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|