MediaWiki  master
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( Wikimedia\Rdbms\ResultWrapper::class )
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 
34  public function testConstructionWithFalseRow() {
35  $row = false;
36  $resultWrapper = $this->getMockResultWrapper( $row );
37 
38  $object = new TitleArrayFromResult( $resultWrapper );
39 
40  $this->assertEquals( $resultWrapper, $object->res );
41  $this->assertSame( 0, $object->key );
42  $this->assertEquals( $row, $object->current );
43  }
44 
48  public function testConstructionWithRow() {
49  $namespace = 0;
50  $title = 'foo';
51  $row = $this->getRowWithTitle( $namespace, $title );
52  $resultWrapper = $this->getMockResultWrapper( $row );
53 
54  $object = new TitleArrayFromResult( $resultWrapper );
55 
56  $this->assertEquals( $resultWrapper, $object->res );
57  $this->assertSame( 0, $object->key );
58  $this->assertInstanceOf( Title::class, $object->current );
59  $this->assertEquals( $namespace, $object->current->mNamespace );
60  $this->assertEquals( $title, $object->current->mTextform );
61  }
62 
63  public static function provideNumberOfRows() {
64  return [
65  [ 0 ],
66  [ 1 ],
67  [ 122 ],
68  ];
69  }
70 
75  public function testCountWithVaryingValues( $numRows ) {
76  $object = new TitleArrayFromResult( $this->getMockResultWrapper(
77  $this->getRowWithTitle(),
78  $numRows
79  ) );
80  $this->assertEquals( $numRows, $object->count() );
81  }
82 
86  public function testCurrentAfterConstruction() {
87  $namespace = 0;
88  $title = 'foo';
89  $row = $this->getRowWithTitle( $namespace, $title );
90  $object = new TitleArrayFromResult( $this->getMockResultWrapper( $row ) );
91  $this->assertInstanceOf( Title::class, $object->current() );
92  $this->assertEquals( $namespace, $object->current->mNamespace );
93  $this->assertEquals( $title, $object->current->mTextform );
94  }
95 
96  public function provideTestValid() {
97  return [
98  [ $this->getRowWithTitle(), true ],
99  [ false, false ],
100  ];
101  }
102 
107  public function testValid( $input, $expected ) {
108  $object = new TitleArrayFromResult( $this->getMockResultWrapper( $input ) );
109  $this->assertEquals( $expected, $object->valid() );
110  }
111 
112  // @todo unit test for key()
113  // @todo unit test for next()
114  // @todo unit test for rewind()
115 }
testValid( $input, $expected)
provideTestValid TitleArrayFromResult::valid
testCurrentAfterConstruction()
TitleArrayFromResult::current.
if(is_array( $mode)) switch( $mode) $input
getRowWithTitle( $namespace=3, $title='foo')
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
getMockResultWrapper( $row=null, $numRows=1)
testCountWithVaryingValues( $numRows)
provideNumberOfRows TitleArrayFromResult::count
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:1971
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
testConstructionWithRow()
TitleArrayFromResult::__construct.
testConstructionWithFalseRow()
TitleArrayFromResult::__construct.