2016-08-03 15:41:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group Echo
|
2018-09-12 20:31:46 +00:00
|
|
|
* @group Database
|
2016-08-03 15:41:50 +00:00
|
|
|
*/
|
|
|
|
class MWEchoThankYouEditTest extends MediaWikiTestCase {
|
|
|
|
|
2019-10-09 22:57:35 +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
|
|
|
/**
|
2020-06-16 04:03:45 +00:00
|
|
|
* @covers \EchoHooks::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
|
|
|
|
$notificationMapper = new EchoNotificationMapper();
|
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 );
|
|
|
|
|
|
|
|
/** @var EchoNotification $notification */
|
|
|
|
$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
|
|
|
/**
|
2020-06-16 04:03:45 +00:00
|
|
|
* @covers \EchoHooks::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
|
|
|
|
$notificationMapper = new EchoNotificationMapper();
|
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 );
|
|
|
|
|
|
|
|
/** @var EchoNotification $notification */
|
|
|
|
$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 ) {
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|