MediaWiki
REL1_24
|
00001 <?php 00002 00007 class TitleArrayFromResultTest extends MediaWikiTestCase { 00008 00009 private function getMockResultWrapper( $row = null, $numRows = 1 ) { 00010 $resultWrapper = $this->getMockBuilder( 'ResultWrapper' ) 00011 ->disableOriginalConstructor(); 00012 00013 $resultWrapper = $resultWrapper->getMock(); 00014 $resultWrapper->expects( $this->atLeastOnce() ) 00015 ->method( 'current' ) 00016 ->will( $this->returnValue( $row ) ); 00017 $resultWrapper->expects( $this->any() ) 00018 ->method( 'numRows' ) 00019 ->will( $this->returnValue( $numRows ) ); 00020 00021 return $resultWrapper; 00022 } 00023 00024 private function getRowWithTitle( $namespace = 3, $title = 'foo' ) { 00025 $row = new stdClass(); 00026 $row->page_namespace = $namespace; 00027 $row->page_title = $title; 00028 return $row; 00029 } 00030 00031 private function getTitleArrayFromResult( $resultWrapper ) { 00032 return new TitleArrayFromResult( $resultWrapper ); 00033 } 00034 00038 public function testConstructionWithFalseRow() { 00039 $row = false; 00040 $resultWrapper = $this->getMockResultWrapper( $row ); 00041 00042 $object = $this->getTitleArrayFromResult( $resultWrapper ); 00043 00044 $this->assertEquals( $resultWrapper, $object->res ); 00045 $this->assertSame( 0, $object->key ); 00046 $this->assertEquals( $row, $object->current ); 00047 } 00048 00052 public function testConstructionWithRow() { 00053 $namespace = 0; 00054 $title = 'foo'; 00055 $row = $this->getRowWithTitle( $namespace, $title ); 00056 $resultWrapper = $this->getMockResultWrapper( $row ); 00057 00058 $object = $this->getTitleArrayFromResult( $resultWrapper ); 00059 00060 $this->assertEquals( $resultWrapper, $object->res ); 00061 $this->assertSame( 0, $object->key ); 00062 $this->assertInstanceOf( 'Title', $object->current ); 00063 $this->assertEquals( $namespace, $object->current->mNamespace ); 00064 $this->assertEquals( $title, $object->current->mTextform ); 00065 } 00066 00067 public static function provideNumberOfRows() { 00068 return array( 00069 array( 0 ), 00070 array( 1 ), 00071 array( 122 ), 00072 ); 00073 } 00074 00079 public function testCountWithVaryingValues( $numRows ) { 00080 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( 00081 $this->getRowWithTitle(), 00082 $numRows 00083 ) ); 00084 $this->assertEquals( $numRows, $object->count() ); 00085 } 00086 00090 public function testCurrentAfterConstruction() { 00091 $namespace = 0; 00092 $title = 'foo'; 00093 $row = $this->getRowWithTitle( $namespace, $title ); 00094 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $row ) ); 00095 $this->assertInstanceOf( 'Title', $object->current() ); 00096 $this->assertEquals( $namespace, $object->current->mNamespace ); 00097 $this->assertEquals( $title, $object->current->mTextform ); 00098 } 00099 00100 public function provideTestValid() { 00101 return array( 00102 array( $this->getRowWithTitle(), true ), 00103 array( false, false ), 00104 ); 00105 } 00106 00111 public function testValid( $input, $expected ) { 00112 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $input ) ); 00113 $this->assertEquals( $expected, $object->valid() ); 00114 } 00115 00116 //@todo unit test for key() 00117 //@todo unit test for next() 00118 //@todo unit test for rewind() 00119 }