MediaWiki  1.23.1
UserArrayFromResultTest.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 getRowWithUsername( $username = 'fooUser' ) {
25  $row = new stdClass();
26  $row->user_name = $username;
27  return $row;
28  }
29 
30  private function getUserArrayFromResult( $resultWrapper ) {
31  return new UserArrayFromResult( $resultWrapper );
32  }
33 
37  public function testConstructionWithFalseRow() {
38  $row = false;
39  $resultWrapper = $this->getMockResultWrapper( $row );
40 
41  $object = $this->getUserArrayFromResult( $resultWrapper );
42 
43  $this->assertEquals( $resultWrapper, $object->res );
44  $this->assertSame( 0, $object->key );
45  $this->assertEquals( $row, $object->current );
46  }
47 
51  public function testConstructionWithRow() {
52  $username = 'addshore';
53  $row = $this->getRowWithUsername( $username );
54  $resultWrapper = $this->getMockResultWrapper( $row );
55 
56  $object = $this->getUserArrayFromResult( $resultWrapper );
57 
58  $this->assertEquals( $resultWrapper, $object->res );
59  $this->assertSame( 0, $object->key );
60  $this->assertInstanceOf( 'User', $object->current );
61  $this->assertEquals( $username, $object->current->mName );
62  }
63 
64  public function provideNumberOfRows() {
65  return array(
66  array( 0 ),
67  array( 1 ),
68  array( 122 ),
69  );
70  }
71 
76  public function testCountWithVaryingValues( $numRows ) {
77  $object = $this->getUserArrayFromResult( $this->getMockResultWrapper( $this->getRowWithUsername(), $numRows ) );
78  $this->assertEquals( $numRows, $object->count() );
79  }
80 
84  public function testCurrentAfterConstruction() {
85  $username = 'addshore';
86  $userRow = $this->getRowWithUsername( $username );
87  $object = $this->getUserArrayFromResult( $this->getMockResultWrapper( $userRow ) );
88  $this->assertInstanceOf( 'User', $object->current() );
89  $this->assertEquals( $username, $object->current()->mName );
90  }
91 
92  public function provideTestValid() {
93  return array(
94  array( $this->getRowWithUsername(), true ),
95  array( false, false ),
96  );
97  }
98 
103  public function testValid( $input, $expected ) {
104  $object = $this->getUserArrayFromResult( $this->getMockResultWrapper( $input ) );
105  $this->assertEquals( $expected, $object->valid() );
106  }
107 
108  //@todo unit test for key()
109  //@todo unit test for next()
110  //@todo unit test for rewind()
111 }
UserArrayFromResultTest\testCurrentAfterConstruction
testCurrentAfterConstruction()
@covers UserArrayFromResult::current
Definition: UserArrayFromResultTest.php:84
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
UserArrayFromResultTest\provideNumberOfRows
provideNumberOfRows()
Definition: UserArrayFromResultTest.php:64
UserArrayFromResultTest\getRowWithUsername
getRowWithUsername( $username='fooUser')
Definition: UserArrayFromResultTest.php:24
UserArrayFromResult
return false to override stock group addition can be modified UserArrayFromResult
Definition: hooks.txt:2697
UserArrayFromResultTest\testConstructionWithRow
testConstructionWithRow()
@covers UserArrayFromResult::__construct
Definition: UserArrayFromResultTest.php:51
UserArrayFromResultTest
Definition: UserArrayFromResultTest.php:7
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
UserArrayFromResultTest\provideTestValid
provideTestValid()
Definition: UserArrayFromResultTest.php:92
UserArrayFromResultTest\getMockResultWrapper
getMockResultWrapper( $row=null, $numRows=1)
Definition: UserArrayFromResultTest.php:9
UserArrayFromResultTest\testCountWithVaryingValues
testCountWithVaryingValues( $numRows)
@dataProvider provideNumberOfRows @covers UserArrayFromResult::count
Definition: UserArrayFromResultTest.php:76
UserArrayFromResultTest\testValid
testValid( $input, $expected)
@dataProvider provideTestValid @covers UserArrayFromResult::valid
Definition: UserArrayFromResultTest.php:103
UserArrayFromResultTest\testConstructionWithFalseRow
testConstructionWithFalseRow()
@covers UserArrayFromResult::__construct
Definition: UserArrayFromResultTest.php:37
UserArrayFromResultTest\getUserArrayFromResult
getUserArrayFromResult( $resultWrapper)
Definition: UserArrayFromResultTest.php:30