| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Log; |
| 4 |
|
| 5 |
use DatabaseLogEntry; |
| 6 |
use LogPage; |
| 7 |
use MediaWiki\MainConfigNames; |
| 8 |
use MediaWiki\User\UserIdentityValue; |
| 9 |
use MockTitleTrait; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class LogPageTest extends \MediaWikiIntegrationTestCase { |
| 16 |
use MockTitleTrait; |
| 17 |
|
| 18 |
protected function setUp(): void { |
| 19 |
parent::setUp(); |
| 20 |
|
| 21 |
$this->overrideConfigValues( [ |
| 22 |
MainConfigNames::LogNames => [ |
| 23 |
'test_test' => 'testing-log-message' |
| 24 |
], |
| 25 |
MainConfigNames::LogHeaders => [ |
| 26 |
'test_test' => 'testing-log-header' |
| 27 |
], |
| 28 |
MainConfigNames::LogRestrictions => [ |
| 29 |
'test_test' => 'testing-log-restriction' |
| 30 |
] |
| 31 |
] ); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function testConstruct() { |
| 42 |
$logPage = new LogPage( 'test_test' ); |
| 43 |
$this->assertSame( 'testing-log-message', $logPage->getName()->getKey() ); |
| 44 |
$this->assertSame( 'testing-log-header', $logPage->getDescription()->getKey() ); |
| 45 |
$this->assertSame( 'testing-log-restriction', $logPage->getRestriction() ); |
| 46 |
$this->assertTrue( $logPage->isRestricted() ); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function testAddEntrySetsProperties() { |
| 56 |
$logPage = new LogPage( 'test_test' ); |
| 57 |
$user = new UserIdentityValue( 1, 'Bar' ); |
| 58 |
$logPage->addEntry( |
| 59 |
'test_action', |
| 60 |
$this->makeMockTitle( __METHOD__ ), |
| 61 |
'testing_comment', |
| 62 |
[ 'param_one', 'param_two' ], |
| 63 |
$user |
| 64 |
); |
| 65 |
$this->assertSame( 'testing_comment', $logPage->getComment() ); |
| 66 |
$this->assertStringContainsString( 'testing_comment', $logPage->getRcComment() ); |
| 67 |
$this->assertStringContainsString( 'testing_comment', $logPage->getRcCommentIRC() ); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public function testAddEntrySave() { |
| 74 |
$logPage = new LogPage( 'test_test' ); |
| 75 |
$user = new UserIdentityValue( 1, 'Foo' ); |
| 76 |
$title = $this->makeMockTitle( __METHOD__ ); |
| 77 |
$id = $logPage->addEntry( |
| 78 |
'test_action', |
| 79 |
$title, |
| 80 |
'testing_comment', |
| 81 |
[ 'param_one', 'param_two' ], |
| 82 |
$user |
| 83 |
); |
| 84 |
|
| 85 |
$savedLogEntry = DatabaseLogEntry::newFromId( $id, $this->getDb() ); |
| 86 |
$this->assertNotNull( $savedLogEntry ); |
| 87 |
$this->assertSame( 'test_test', $savedLogEntry->getType() ); |
| 88 |
$this->assertSame( 'test_action', $savedLogEntry->getSubtype() ); |
| 89 |
$this->assertSame( 'testing_comment', $savedLogEntry->getComment() ); |
| 90 |
$this->assertArrayEquals( [ 'param_one', 'param_two' ], $savedLogEntry->getParameters() ); |
| 91 |
$this->assertTrue( $title->equals( $savedLogEntry->getTarget() ) ); |
| 92 |
$this->assertTrue( $user->equals( $savedLogEntry->getPerformerIdentity() ) ); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public function testUnknownAction() { |
| 99 |
$title = $this->makeMockTitle( 'Test Title' ); |
| 100 |
$text = LogPage::actionText( 'unknown', 'action', $title, null, [ 'discarded' ] ); |
| 101 |
$this->assertSame( 'performed unknown action "unknown/action" on [[Test Title]]', $text ); |
| 102 |
} |
| 103 |
} |