Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / specials / UncategorizedCategoriesPageTest.php
1 <?php
2 /**
3 * Tests for Special:Uncategorizedcategories
4 */
5 class UncategorizedCategoriesPageTest extends \MediaWikiUnitTestCase {
6
7 protected function setUp() {
8 parent::setUp();
9
10 $loadBalancerMock = $this->createMock( LoadBalancer::class );
11
12 $loadBalancerMock->expects( $this->any() )
13 ->method( 'getConnection' )
14 ->willReturn( new DatabaseTestHelper( __CLASS__ ) );
15
16 $loadBalancerMockFactory = function () use ( $loadBalancerMock ): LoadBalancer {
17 return $loadBalancerMock;
18 };
19
20 $this->overrideMwServices( [ 'DBLoadBalancer' => $loadBalancerMockFactory ] );
21 }
22
23 /**
24 * @dataProvider provideTestGetQueryInfoData
25 * @covers UncategorizedCategoriesPage::getQueryInfo
26 */
27 public function testGetQueryInfo( $msgContent, $expected ) {
28 $msg = new RawMessage( $msgContent );
29 $mockContext = $this->getMockBuilder( RequestContext::class )->getMock();
30 $mockContext->method( 'msg' )->willReturn( $msg );
31 $special = new UncategorizedCategoriesPage();
32 $special->setContext( $mockContext );
33 $this->assertEquals( [
34 'tables' => [
35 0 => 'page',
36 1 => 'categorylinks',
37 ],
38 'fields' => [
39 'namespace' => 'page_namespace',
40 'title' => 'page_title',
41 'value' => 'page_title',
42 ],
43 'conds' => [
44 0 => 'cl_from IS NULL',
45 'page_namespace' => 14,
46 'page_is_redirect' => 0,
47 ] + $expected,
48 'join_conds' => [
49 'categorylinks' => [
50 0 => 'LEFT JOIN',
51 1 => 'cl_from = page_id',
52 ],
53 ],
54 ], $special->getQueryInfo() );
55 }
56
57 public function provideTestGetQueryInfoData() {
58 return [
59 [
60 "* Stubs\n* Test\n* *\n* * test123",
61 [ 1 => "page_title not in ( 'Stubs','Test','*','*_test123' )" ]
62 ],
63 [
64 "Stubs\n* Test\n* *\n* * test123",
65 [ 1 => "page_title not in ( 'Test','*','*_test123' )" ]
66 ],
67 [
68 "* StubsTest\n* *\n* * test123",
69 [ 1 => "page_title not in ( 'StubsTest','*','*_test123' )" ]
70 ],
71 [ "", [] ],
72 [ "\n\n\n", [] ],
73 [ "\n", [] ],
74 [ "Test\n*Test2", [ 1 => "page_title not in ( 'Test2' )" ] ],
75 [ "Test", [] ],
76 [ "*Test\nTest2", [ 1 => "page_title not in ( 'Test' )" ] ],
77 [ "Test\nTest2", [] ],
78 ];
79 }
80 }