2014-01-26 17:46:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-27 09:59:31 +00:00
|
|
|
* @author Addshore
|
2014-01-26 17:46:20 +00:00
|
|
|
* @covers TitleArrayFromResult
|
|
|
|
|
*/
|
2015-06-09 17:02:48 +00:00
|
|
|
class TitleArrayFromResultTest extends PHPUnit_Framework_TestCase {
|
2014-01-26 17:46:20 +00:00
|
|
|
|
|
|
|
|
private function getMockResultWrapper( $row = null, $numRows = 1 ) {
|
|
|
|
|
$resultWrapper = $this->getMockBuilder( 'ResultWrapper' )
|
|
|
|
|
->disableOriginalConstructor();
|
|
|
|
|
|
|
|
|
|
$resultWrapper = $resultWrapper->getMock();
|
|
|
|
|
$resultWrapper->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'current' )
|
|
|
|
|
->will( $this->returnValue( $row ) );
|
|
|
|
|
$resultWrapper->expects( $this->any() )
|
|
|
|
|
->method( 'numRows' )
|
|
|
|
|
->will( $this->returnValue( $numRows ) );
|
|
|
|
|
|
|
|
|
|
return $resultWrapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getRowWithTitle( $namespace = 3, $title = 'foo' ) {
|
|
|
|
|
$row = new stdClass();
|
|
|
|
|
$row->page_namespace = $namespace;
|
|
|
|
|
$row->page_title = $title;
|
|
|
|
|
return $row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getTitleArrayFromResult( $resultWrapper ) {
|
|
|
|
|
return new TitleArrayFromResult( $resultWrapper );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers TitleArrayFromResult::__construct
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructionWithFalseRow() {
|
|
|
|
|
$row = false;
|
|
|
|
|
$resultWrapper = $this->getMockResultWrapper( $row );
|
|
|
|
|
|
|
|
|
|
$object = $this->getTitleArrayFromResult( $resultWrapper );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $resultWrapper, $object->res );
|
|
|
|
|
$this->assertSame( 0, $object->key );
|
|
|
|
|
$this->assertEquals( $row, $object->current );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers TitleArrayFromResult::__construct
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructionWithRow() {
|
|
|
|
|
$namespace = 0;
|
|
|
|
|
$title = 'foo';
|
|
|
|
|
$row = $this->getRowWithTitle( $namespace, $title );
|
|
|
|
|
$resultWrapper = $this->getMockResultWrapper( $row );
|
|
|
|
|
|
|
|
|
|
$object = $this->getTitleArrayFromResult( $resultWrapper );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $resultWrapper, $object->res );
|
|
|
|
|
$this->assertSame( 0, $object->key );
|
|
|
|
|
$this->assertInstanceOf( 'Title', $object->current );
|
|
|
|
|
$this->assertEquals( $namespace, $object->current->mNamespace );
|
|
|
|
|
$this->assertEquals( $title, $object->current->mTextform );
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideNumberOfRows() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 0 ],
|
|
|
|
|
[ 1 ],
|
|
|
|
|
[ 122 ],
|
|
|
|
|
];
|
2014-01-26 17:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideNumberOfRows
|
|
|
|
|
* @covers TitleArrayFromResult::count
|
|
|
|
|
*/
|
|
|
|
|
public function testCountWithVaryingValues( $numRows ) {
|
2014-04-24 12:50:36 +00:00
|
|
|
$object = $this->getTitleArrayFromResult( $this->getMockResultWrapper(
|
|
|
|
|
$this->getRowWithTitle(),
|
|
|
|
|
$numRows
|
|
|
|
|
) );
|
2014-01-26 17:46:20 +00:00
|
|
|
$this->assertEquals( $numRows, $object->count() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers TitleArrayFromResult::current
|
|
|
|
|
*/
|
|
|
|
|
public function testCurrentAfterConstruction() {
|
|
|
|
|
$namespace = 0;
|
|
|
|
|
$title = 'foo';
|
|
|
|
|
$row = $this->getRowWithTitle( $namespace, $title );
|
|
|
|
|
$object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $row ) );
|
|
|
|
|
$this->assertInstanceOf( 'Title', $object->current() );
|
|
|
|
|
$this->assertEquals( $namespace, $object->current->mNamespace );
|
|
|
|
|
$this->assertEquals( $title, $object->current->mTextform );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideTestValid() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ $this->getRowWithTitle(), true ],
|
|
|
|
|
[ false, false ],
|
|
|
|
|
];
|
2014-01-26 17:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideTestValid
|
|
|
|
|
* @covers TitleArrayFromResult::valid
|
|
|
|
|
*/
|
|
|
|
|
public function testValid( $input, $expected ) {
|
|
|
|
|
$object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $input ) );
|
|
|
|
|
$this->assertEquals( $expected, $object->valid() );
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// @todo unit test for key()
|
|
|
|
|
// @todo unit test for next()
|
|
|
|
|
// @todo unit test for rewind()
|
2014-03-20 18:59:20 +00:00
|
|
|
}
|