4 * @author Adam Shorland
5 * @covers TitleArrayFromResult
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() )
16 ->will( $this->returnValue( $row ) );
17 $resultWrapper->expects( $this->any() )
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;
31 private function getTitleArrayFromResult( $resultWrapper ) {
32 return new TitleArrayFromResult( $resultWrapper );
36 * @covers TitleArrayFromResult::__construct
38 public function testConstructionWithFalseRow() {
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
);
50 * @covers TitleArrayFromResult::__construct
52 public function testConstructionWithRow() {
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() {
76 * @dataProvider provideNumberOfRows
77 * @covers TitleArrayFromResult::count
79 public function testCountWithVaryingValues( $numRows ) {
80 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper(
81 $this->getRowWithTitle(),
84 $this->assertEquals( $numRows, $object->count() );
88 * @covers TitleArrayFromResult::current
90 public function testCurrentAfterConstruction() {
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() {
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()