Debian Codegraph @

tests/phpunit/includes/specials/SpecialLogTest.php

raw symbols SCIP
1 <?php
2 /**
3 * @license GPL-2.0-or-later
4 * @author Legoktm
5 */
6
7 use MediaWiki\Context\DerivativeContext;
8 use MediaWiki\Context\RequestContext;
9 use MediaWiki\Request\FauxRequest;
10 use MediaWiki\Revision\RevisionRecord;
11 use MediaWiki\SpecialPage\SpecialPage;
12 use MediaWiki\Specials\SpecialLog;
13
14 /**
15 * @group Database
16 * @covers \MediaWiki\Specials\SpecialLog
17 */
18 class SpecialLogTest extends SpecialPageTestBase {
19
20 /**
21 * Returns a new instance of the special page under test.
22 *
23 * @return SpecialPage
24 */
25 protected function newSpecialPage() {
26 $services = $this->getServiceContainer();
27 return new SpecialLog(
28 $services->getLinkBatchFactory(),
29 $services->getConnectionProvider(),
30 $services->getActorNormalization(),
31 $services->getUserIdentityLookup(),
32 $services->getUserNameUtils(),
33 $services->getLogFormatterFactory()
34 );
35 }
36
37 /**
38 * Verify that no exception was thrown for an invalid date
39 * @see T201411
40 */
41 public function testInvalidDate() {
42 [ $html, ] = $this->executeSpecialPage(
43 '',
44 // There is no 13th month
45 new FauxRequest( [ 'wpdate' => '2018-13-01' ] ),
46 'qqx'
47 );
48 $this->assertStringContainsString( '(log-summary)', $html );
49 }
50
51 public function testSuppressionLog() {
52 // Have "BadGuy" create a revision
53 $user = ( new TestUser( 'BadGuy' ) )->getUser();
54 $title = $this->insertPage( 'Foo', 'Bar', null, $user )['title'];
55 $revId = $title->getLatestRevID();
56
57 $context = new DerivativeContext( RequestContext::getMain() );
58 $context->setUser( $this->getTestUser( [ 'sysop', 'suppress' ] )->getUser() );
59 // Hide our revision's comment
60 $list = RevisionDeleter::createList( 'revision', $context, $title, [ $revId ] );
61 $status = $list->setVisibility( [
62 'value' => [
63 RevisionRecord::DELETED_RESTRICTED => 1,
64 RevisionRecord::DELETED_COMMENT => 1
65 ],
66 'comment' => 'SpecialLogTest'
67 ] );
68 $this->assertStatusGood( $status );
69
70 // Allow everyone to read the suppression log
71 $this->mergeMwGlobalArrayValue(
72 'wgGroupPermissions', [
73 '*' => [
74 'suppressionlog' => true
75 ]
76 ]
77 );
78
79 [ $html, ] = $this->executeSpecialPage(
80 'suppress',
81 new FauxRequest( [ 'offender' => 'BadGuy' ] ),
82 'qqx'
83 );
84 $this->assertStringNotContainsString( '(logempty)', $html );
85 $this->assertStringContainsString( '(logentry-suppress-revision', $html );
86
87 // Full suppression log
88 [ $html, ] = $this->executeSpecialPage(
89 'suppress',
90 new FauxRequest(),
91 'qqx'
92 );
93 $this->assertStringNotContainsString( '(logempty)', $html );
94 $this->assertStringContainsString( '(logentry-suppress-revision', $html );
95
96 // Suppression log for unknown user should be empty
97 [ $html, ] = $this->executeSpecialPage(
98 'suppress',
99 new FauxRequest( [ 'offender' => 'GoodGuy' ] ),
100 'qqx'
101 );
102 $this->assertStringContainsString( '(logempty)', $html );
103 $this->assertStringNotContainsString( '(logentry-suppress-revision', $html );
104 }
105
106 }