Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / TitleArrayFromResultTest.php
blobaad435e77713762904150ad96f25ce2e37db0d0c
1 <?php
3 /**
4 * @author Adam Shorland
5 * @covers TitleArrayFromResult
6 */
7 class TitleArrayFromResultTest extends PHPUnit_Framework_TestCase {
9 private function getMockResultWrapper( $row = null, $numRows = 1 ) {
10 $resultWrapper = $this->getMockBuilder( 'ResultWrapper' )
11 ->disableOriginalConstructor();
13 $resultWrapper = $resultWrapper->getMock();
14 $resultWrapper->expects( $this->atLeastOnce() )
15 ->method( 'current' )
16 ->will( $this->returnValue( $row ) );
17 $resultWrapper->expects( $this->any() )
18 ->method( 'numRows' )
19 ->will( $this->returnValue( $numRows ) );
21 return $resultWrapper;
24 private function getRowWithTitle( $namespace = 3, $title = 'foo' ) {
25 $row = new stdClass();
26 $row->page_namespace = $namespace;
27 $row->page_title = $title;
28 return $row;
31 private function getTitleArrayFromResult( $resultWrapper ) {
32 return new TitleArrayFromResult( $resultWrapper );
35 /**
36 * @covers TitleArrayFromResult::__construct
38 public function testConstructionWithFalseRow() {
39 $row = false;
40 $resultWrapper = $this->getMockResultWrapper( $row );
42 $object = $this->getTitleArrayFromResult( $resultWrapper );
44 $this->assertEquals( $resultWrapper, $object->res );
45 $this->assertSame( 0, $object->key );
46 $this->assertEquals( $row, $object->current );
49 /**
50 * @covers TitleArrayFromResult::__construct
52 public function testConstructionWithRow() {
53 $namespace = 0;
54 $title = 'foo';
55 $row = $this->getRowWithTitle( $namespace, $title );
56 $resultWrapper = $this->getMockResultWrapper( $row );
58 $object = $this->getTitleArrayFromResult( $resultWrapper );
60 $this->assertEquals( $resultWrapper, $object->res );
61 $this->assertSame( 0, $object->key );
62 $this->assertInstanceOf( 'Title', $object->current );
63 $this->assertEquals( $namespace, $object->current->mNamespace );
64 $this->assertEquals( $title, $object->current->mTextform );
67 public static function provideNumberOfRows() {
68 return array(
69 array( 0 ),
70 array( 1 ),
71 array( 122 ),
75 /**
76 * @dataProvider provideNumberOfRows
77 * @covers TitleArrayFromResult::count
79 public function testCountWithVaryingValues( $numRows ) {
80 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper(
81 $this->getRowWithTitle(),
82 $numRows
83 ) );
84 $this->assertEquals( $numRows, $object->count() );
87 /**
88 * @covers TitleArrayFromResult::current
90 public function testCurrentAfterConstruction() {
91 $namespace = 0;
92 $title = 'foo';
93 $row = $this->getRowWithTitle( $namespace, $title );
94 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $row ) );
95 $this->assertInstanceOf( 'Title', $object->current() );
96 $this->assertEquals( $namespace, $object->current->mNamespace );
97 $this->assertEquals( $title, $object->current->mTextform );
100 public function provideTestValid() {
101 return array(
102 array( $this->getRowWithTitle(), true ),
103 array( false, false ),
108 * @dataProvider provideTestValid
109 * @covers TitleArrayFromResult::valid
111 public function testValid( $input, $expected ) {
112 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $input ) );
113 $this->assertEquals( $expected, $object->valid() );
116 // @todo unit test for key()
117 // @todo unit test for next()
118 // @todo unit test for rewind()