Merge "Make Special:MovePage note about redirects dependent on content model"
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / db / DatabaseOracleTest.php
1 <?php
2
3 class DatabaseOracleTest extends MediaWikiUnitTestCase {
4
5 /**
6 * @return PHPUnit_Framework_MockObject_MockObject|DatabaseOracle
7 */
8 private function getMockDb() {
9 return $this->getMockBuilder( DatabaseOracle::class )
10 ->disableOriginalConstructor()
11 ->setMethods( null )
12 ->getMock();
13 }
14
15 public function provideBuildSubstring() {
16 yield [ 'someField', 1, 2, 'SUBSTR(someField,1,2)' ];
17 yield [ 'someField', 1, null, 'SUBSTR(someField,1)' ];
18 }
19
20 /**
21 * @covers DatabaseOracle::buildSubstring
22 * @dataProvider provideBuildSubstring
23 */
24 public function testBuildSubstring( $input, $start, $length, $expected ) {
25 $mockDb = $this->getMockDb();
26 $output = $mockDb->buildSubstring( $input, $start, $length );
27 $this->assertSame( $expected, $output );
28 }
29
30 public function provideBuildSubstring_invalidParams() {
31 yield [ -1, 1 ];
32 yield [ 1, -1 ];
33 yield [ 1, 'foo' ];
34 yield [ 'foo', 1 ];
35 yield [ null, 1 ];
36 yield [ 0, 1 ];
37 }
38
39 /**
40 * @covers DatabaseOracle::buildSubstring
41 * @dataProvider provideBuildSubstring_invalidParams
42 */
43 public function testBuildSubstring_invalidParams( $start, $length ) {
44 $mockDb = $this->getMockDb();
45 $this->setExpectedException( InvalidArgumentException::class );
46 $mockDb->buildSubstring( 'foo', $start, $length );
47 }
48
49 }