2016-08-03 15:41:50 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-22 15:31:00 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Test;
|
|
|
|
|
2024-11-07 20:16:46 +00:00
|
|
|
use MediaWiki\Deferred\DeferredUpdates;
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DbFactory;
|
2022-11-02 20:47:04 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2024-02-22 15:31:00 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2024-04-12 19:50:43 +00:00
|
|
|
use Wikimedia\Rdbms\Platform\ISQLPlatform;
|
2022-11-02 20:47:04 +00:00
|
|
|
|
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
|
|
|
*/
|
2023-08-12 19:07:15 +00:00
|
|
|
class ThankYouEditTest extends MediaWikiIntegrationTestCase {
|
2016-08-03 15:41:50 +00:00
|
|
|
|
2017-03-22 09:32:30 +00:00
|
|
|
private function deleteEchoData() {
|
2022-11-12 07:19:00 +00:00
|
|
|
$db = DbFactory::newFromDefault()->getEchoDb( DB_PRIMARY );
|
2024-04-12 19:50:43 +00:00
|
|
|
$db->newDeleteQueryBuilder()
|
|
|
|
->deleteFrom( 'echo_event' )
|
|
|
|
->where( ISQLPlatform::ALL_ROWS )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->execute();
|
|
|
|
$db->newDeleteQueryBuilder()
|
|
|
|
->deleteFrom( 'echo_notification' )
|
|
|
|
->where( ISQLPlatform::ALL_ROWS )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->execute();
|
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
|
2023-07-15 20:32:16 +00:00
|
|
|
$this->editPage( $title, 'this is my first edit', '', NS_MAIN, $user );
|
2024-11-07 20:16:46 +00:00
|
|
|
DeferredUpdates::tryOpportunisticExecute();
|
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( 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' );
|
2023-07-15 20:32:16 +00:00
|
|
|
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
|
2016-08-03 15:41:50 +00:00
|
|
|
|
|
|
|
// 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++ ) {
|
2023-07-15 20:32:16 +00:00
|
|
|
$this->editPage( $page, "this is edit #$i", '', NS_MAIN, $user );
|
2016-08-03 15:41:50 +00:00
|
|
|
}
|
2024-11-07 20:16:46 +00:00
|
|
|
DeferredUpdates::tryOpportunisticExecute();
|
2023-07-15 20:32:16 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|