MediaWiki REL1_31
TitleArrayFromResultTest.php
Go to the documentation of this file.
1<?php
2
7class TitleArrayFromResultTest extends PHPUnit\Framework\TestCase {
8
9 use MediaWikiCoversValidator;
10
11 private function getMockResultWrapper( $row = null, $numRows = 1 ) {
12 $resultWrapper = $this->getMockBuilder( Wikimedia\Rdbms\ResultWrapper::class )
13 ->disableOriginalConstructor();
14
15 $resultWrapper = $resultWrapper->getMock();
16 $resultWrapper->expects( $this->atLeastOnce() )
17 ->method( 'current' )
18 ->will( $this->returnValue( $row ) );
19 $resultWrapper->expects( $this->any() )
20 ->method( 'numRows' )
21 ->will( $this->returnValue( $numRows ) );
22
23 return $resultWrapper;
24 }
25
26 private function getRowWithTitle( $namespace = 3, $title = 'foo' ) {
27 $row = new stdClass();
28 $row->page_namespace = $namespace;
29 $row->page_title = $title;
30 return $row;
31 }
32
33 private function getTitleArrayFromResult( $resultWrapper ) {
34 return new TitleArrayFromResult( $resultWrapper );
35 }
36
40 public function testConstructionWithFalseRow() {
41 $row = false;
42 $resultWrapper = $this->getMockResultWrapper( $row );
43
44 $object = $this->getTitleArrayFromResult( $resultWrapper );
45
46 $this->assertEquals( $resultWrapper, $object->res );
47 $this->assertSame( 0, $object->key );
48 $this->assertEquals( $row, $object->current );
49 }
50
54 public function testConstructionWithRow() {
55 $namespace = 0;
56 $title = 'foo';
57 $row = $this->getRowWithTitle( $namespace, $title );
58 $resultWrapper = $this->getMockResultWrapper( $row );
59
60 $object = $this->getTitleArrayFromResult( $resultWrapper );
61
62 $this->assertEquals( $resultWrapper, $object->res );
63 $this->assertSame( 0, $object->key );
64 $this->assertInstanceOf( Title::class, $object->current );
65 $this->assertEquals( $namespace, $object->current->mNamespace );
66 $this->assertEquals( $title, $object->current->mTextform );
67 }
68
69 public static function provideNumberOfRows() {
70 return [
71 [ 0 ],
72 [ 1 ],
73 [ 122 ],
74 ];
75 }
76
81 public function testCountWithVaryingValues( $numRows ) {
82 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper(
83 $this->getRowWithTitle(),
84 $numRows
85 ) );
86 $this->assertEquals( $numRows, $object->count() );
87 }
88
92 public function testCurrentAfterConstruction() {
93 $namespace = 0;
94 $title = 'foo';
95 $row = $this->getRowWithTitle( $namespace, $title );
96 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $row ) );
97 $this->assertInstanceOf( Title::class, $object->current() );
98 $this->assertEquals( $namespace, $object->current->mNamespace );
99 $this->assertEquals( $title, $object->current->mTextform );
100 }
101
102 public function provideTestValid() {
103 return [
104 [ $this->getRowWithTitle(), true ],
105 [ false, false ],
106 ];
107 }
108
113 public function testValid( $input, $expected ) {
114 $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $input ) );
115 $this->assertEquals( $expected, $object->valid() );
116 }
117
118 // @todo unit test for key()
119 // @todo unit test for next()
120 // @todo unit test for rewind()
121}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
testConstructionWithFalseRow()
TitleArrayFromResult::__construct.
testValid( $input, $expected)
provideTestValid TitleArrayFromResult::valid
testConstructionWithRow()
TitleArrayFromResult::__construct.
testCurrentAfterConstruction()
TitleArrayFromResult::current.
getRowWithTitle( $namespace=3, $title='foo')
testCountWithVaryingValues( $numRows)
provideNumberOfRows TitleArrayFromResult::count
getMockResultWrapper( $row=null, $numRows=1)
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
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:2006
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
if(is_array($mode)) switch( $mode) $input