2016-08-03 15:41:50 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-02 20:47:04 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
|
|
|
|
2016-08-03 15:41:50 +00:00
|
|
|
/**
|
|
|
|
* @group Echo
|
2018-09-12 20:31:46 +00:00
|
|
|
* @group Database
|
2016-08-03 15:41:50 +00:00
|
|
|
*/
|
2021-10-11 22:42:10 +00:00
|
|
|
class MWEchoThankYouEditTest extends MediaWikiIntegrationTestCase {
|
2016-08-03 15:41:50 +00:00
|
|
|
|
2021-07-23 21:23:16 +00:00
|
|
|
protected function setUp(): void {
|
2016-08-03 15:41:50 +00:00
|
|
|
parent::setUp();
|
2017-03-22 09:32:30 +00:00
|
|
|
$this->tablesUsed[] = 'echo_event';
|
|
|
|
$this->tablesUsed[] = 'echo_notification';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function deleteEchoData() {
|
2021-05-03 07:28:02 +00:00
|
|
|
$db = MWEchoDbFactory::newFromDefault()->getEchoDb( DB_PRIMARY );
|
2017-03-22 09:32:30 +00:00
|
|
|
$db->delete( 'echo_event', '*', __METHOD__ );
|
|
|
|
$db->delete( 'echo_notification', '*', __METHOD__ );
|
2016-08-03 15:41:50 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 15:38:07 +00:00
|
|
|
/**
|
2022-04-08 00:28:15 +00:00
|
|
|
* @covers \MediaWiki\Extension\Notifications\Hooks::onPageSaveComplete
|
2018-06-14 15:38:07 +00:00
|
|
|
*/
|
2016-08-03 15:41:50 +00:00
|
|
|
public function testFirstEdit() {
|
|
|
|
// setup
|
2017-03-22 09:32:30 +00:00
|
|
|
$this->deleteEchoData();
|
2016-08-03 15:41:50 +00:00
|
|
|
$user = $this->getMutableTestUser()->getUser();
|
|
|
|
$title = Title::newFromText( 'Help:MWEchoThankYouEditTest_testFirstEdit' );
|
|
|
|
|
|
|
|
// action
|
|
|
|
$this->edit( $title, $user, 'this is my first edit' );
|
|
|
|
|
|
|
|
// assertions
|
2022-11-02 20:47:04 +00:00
|
|
|
$notificationMapper = new NotificationMapper();
|
2016-12-05 18:51:07 +00:00
|
|
|
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
|
2016-08-03 15:41:50 +00:00
|
|
|
$this->assertCount( 1, $notifications );
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
/** @var Notification $notification */
|
2016-08-03 15:41:50 +00:00
|
|
|
$notification = reset( $notifications );
|
2019-10-23 10:28:30 +00:00
|
|
|
$this->assertSame( 1, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) );
|
2016-08-03 15:41:50 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 15:38:07 +00:00
|
|
|
/**
|
2022-04-08 00:28:15 +00:00
|
|
|
* @covers \MediaWiki\Extension\Notifications\Hooks::onPageSaveComplete
|
2018-06-14 15:38:07 +00:00
|
|
|
*/
|
2016-08-03 15:41:50 +00:00
|
|
|
public function testTenthEdit() {
|
|
|
|
// setup
|
2017-03-22 09:32:30 +00:00
|
|
|
$this->deleteEchoData();
|
2016-08-03 15:41:50 +00:00
|
|
|
$user = $this->getMutableTestUser()->getUser();
|
|
|
|
$title = Title::newFromText( 'Help:MWEchoThankYouEditTest_testTenthEdit' );
|
|
|
|
|
|
|
|
// action
|
|
|
|
// we could fast-forward the edit-count to speed things up
|
|
|
|
// but this is the only way to make sure duplicate notifications
|
|
|
|
// are not generated
|
|
|
|
for ( $i = 0; $i < 12; $i++ ) {
|
|
|
|
$this->edit( $title, $user, "this is edit #$i" );
|
2018-10-23 17:44:57 +00:00
|
|
|
// Reload to reflect deferred update
|
|
|
|
$user->clearInstanceCache();
|
2016-08-03 15:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// assertions
|
2022-11-02 20:47:04 +00:00
|
|
|
$notificationMapper = new NotificationMapper();
|
2016-12-05 18:51:07 +00:00
|
|
|
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
|
2016-08-03 15:41:50 +00:00
|
|
|
$this->assertCount( 2, $notifications );
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
/** @var Notification $notification */
|
2016-08-03 15:41:50 +00:00
|
|
|
$notification = reset( $notifications );
|
2019-10-23 10:28:30 +00:00
|
|
|
$this->assertSame( 10, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) );
|
2016-08-03 15:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function edit( Title $title, User $user, $text ) {
|
2022-06-03 21:00:26 +00:00
|
|
|
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2016-08-03 15:41:50 +00:00
|
|
|
$content = ContentHandler::makeContent( $text, $title );
|
2021-06-24 04:54:45 +00:00
|
|
|
$page->doUserEditContent( $content, $user, 'test' );
|
2016-08-03 15:41:50 +00:00
|
|
|
}
|
|
|
|
}
|