MediaWiki  1.28.0
TitleArrayFromResultTest.php
Go to the documentation of this file.
1 <?php
2 
7 class TitleArrayFromResultTest extends PHPUnit_Framework_TestCase {
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 static function provideNumberOfRows() {
68  return [
69  [ 0 ],
70  [ 1 ],
71  [ 122 ],
72  ];
73  }
74 
79  public function testCountWithVaryingValues( $numRows ) {
80  $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper(
81  $this->getRowWithTitle(),
82  $numRows
83  ) );
84  $this->assertEquals( $numRows, $object->count() );
85  }
86 
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 );
98  }
99 
100  public function provideTestValid() {
101  return [
102  [ $this->getRowWithTitle(), true ],
103  [ false, false ],
104  ];
105  }
106 
111  public function testValid( $input, $expected ) {
112  $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $input ) );
113  $this->assertEquals( $expected, $object->valid() );
114  }
115 
116  // @todo unit test for key()
117  // @todo unit test for next()
118  // @todo unit test for rewind()
119 }
testCurrentAfterConstruction()
TitleArrayFromResult::current.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1936
getMockResultWrapper($row=null, $numRows=1)
testCountWithVaryingValues($numRows)
provideNumberOfRows TitleArrayFromResult::count
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getRowWithTitle($namespace=3, $title= 'foo')
testConstructionWithRow()
TitleArrayFromResult::__construct.
testValid($input, $expected)
provideTestValid TitleArrayFromResult::valid
testConstructionWithFalseRow()
TitleArrayFromResult::__construct.