MediaWiki  1.23.15
TitleArrayFromResultTest.php
Go to the documentation of this file.
1 <?php
2 
8 
9  private function getMockResultWrapper( $row = null, $numRows = 1 ) {
10  $resultWrapper = $this->getMockBuilder( 'ResultWrapper' )
11  ->disableOriginalConstructor();
12 
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 ) );
20 
21  return $resultWrapper;
22  }
23 
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;
29  }
30 
31  private function getTitleArrayFromResult( $resultWrapper ) {
32  return new TitleArrayFromResult( $resultWrapper );
33  }
34 
38  public function testConstructionWithFalseRow() {
39  $row = false;
40  $resultWrapper = $this->getMockResultWrapper( $row );
41 
42  $object = $this->getTitleArrayFromResult( $resultWrapper );
43 
44  $this->assertEquals( $resultWrapper, $object->res );
45  $this->assertSame( 0, $object->key );
46  $this->assertEquals( $row, $object->current );
47  }
48 
52  public function testConstructionWithRow() {
53  $namespace = 0;
54  $title = 'foo';
55  $row = $this->getRowWithTitle( $namespace, $title );
56  $resultWrapper = $this->getMockResultWrapper( $row );
57 
58  $object = $this->getTitleArrayFromResult( $resultWrapper );
59 
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 );
65  }
66 
67  public function provideNumberOfRows() {
68  return array(
69  array( 0 ),
70  array( 1 ),
71  array( 122 ),
72  );
73  }
74 
79  public function testCountWithVaryingValues( $numRows ) {
80  $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $this->getRowWithTitle(), $numRows ) );
81  $this->assertEquals( $numRows, $object->count() );
82  }
83 
87  public function testCurrentAfterConstruction() {
88  $namespace = 0;
89  $title = 'foo';
90  $row = $this->getRowWithTitle( $namespace, $title );
91  $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $row ) );
92  $this->assertInstanceOf( 'Title', $object->current() );
93  $this->assertEquals( $namespace, $object->current->mNamespace );
94  $this->assertEquals( $title, $object->current->mTextform );
95  }
96 
97  public function provideTestValid() {
98  return array(
99  array( $this->getRowWithTitle(), true ),
100  array( false, false ),
101  );
102  }
103 
108  public function testValid( $input, $expected ) {
109  $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $input ) );
110  $this->assertEquals( $expected, $object->valid() );
111  }
112 
113  //@todo unit test for key()
114  //@todo unit test for next()
115  //@todo unit test for rewind()
116 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
TitleArrayFromResultTest\testCountWithVaryingValues
testCountWithVaryingValues( $numRows)
@dataProvider provideNumberOfRows @covers TitleArrayFromResult::count
Definition: TitleArrayFromResultTest.php:79
TitleArrayFromResultTest
Definition: TitleArrayFromResultTest.php:7
TitleArrayFromResultTest\provideNumberOfRows
provideNumberOfRows()
Definition: TitleArrayFromResultTest.php:67
TitleArrayFromResultTest\testConstructionWithFalseRow
testConstructionWithFalseRow()
@covers TitleArrayFromResult::__construct
Definition: TitleArrayFromResultTest.php:38
TitleArrayFromResultTest\testConstructionWithRow
testConstructionWithRow()
@covers TitleArrayFromResult::__construct
Definition: TitleArrayFromResultTest.php:52
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
TitleArrayFromResult
Definition: TitleArrayFromResult.php:27
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
TitleArrayFromResultTest\testCurrentAfterConstruction
testCurrentAfterConstruction()
@covers TitleArrayFromResult::current
Definition: TitleArrayFromResultTest.php:87
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
TitleArrayFromResultTest\getRowWithTitle
getRowWithTitle( $namespace=3, $title='foo')
Definition: TitleArrayFromResultTest.php:24
TitleArrayFromResultTest\getTitleArrayFromResult
getTitleArrayFromResult( $resultWrapper)
Definition: TitleArrayFromResultTest.php:31
TitleArrayFromResultTest\getMockResultWrapper
getMockResultWrapper( $row=null, $numRows=1)
Definition: TitleArrayFromResultTest.php:9
TitleArrayFromResultTest\testValid
testValid( $input, $expected)
@dataProvider provideTestValid @covers TitleArrayFromResult::valid
Definition: TitleArrayFromResultTest.php:108
TitleArrayFromResultTest\provideTestValid
provideTestValid()
Definition: TitleArrayFromResultTest.php:97