| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Test; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Notifications\DbFactory; |
| 6 |
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
use MediaWikiIntegrationTestCase; |
| 9 |
use Wikimedia\Rdbms\Platform\ISQLPlatform; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class ThankYouEditTest extends MediaWikiIntegrationTestCase { |
| 16 |
|
| 17 |
private function deleteEchoData() { |
| 18 |
$db = DbFactory::newFromDefault()->getEchoDb( DB_PRIMARY ); |
| 19 |
$db->newDeleteQueryBuilder() |
| 20 |
->deleteFrom( 'echo_event' ) |
| 21 |
->where( ISQLPlatform::ALL_ROWS ) |
| 22 |
->caller( __METHOD__ ) |
| 23 |
->execute(); |
| 24 |
$db->newDeleteQueryBuilder() |
| 25 |
->deleteFrom( 'echo_notification' ) |
| 26 |
->where( ISQLPlatform::ALL_ROWS ) |
| 27 |
->caller( __METHOD__ ) |
| 28 |
->execute(); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public function testFirstEdit() { |
| 35 |
|
| 36 |
$this->deleteEchoData(); |
| 37 |
$user = $this->getMutableTestUser()->getUser(); |
| 38 |
$title = Title::newFromText( 'Help:MWEchoThankYouEditTest_testFirstEdit' ); |
| 39 |
|
| 40 |
|
| 41 |
$this->editPage( $title, 'this is my first edit', '', NS_MAIN, $user ); |
| 42 |
|
| 43 |
|
| 44 |
$notificationMapper = new NotificationMapper(); |
| 45 |
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] ); |
| 46 |
$this->assertCount( 1, $notifications ); |
| 47 |
|
| 48 |
|
| 49 |
$notification = reset( $notifications ); |
| 50 |
$this->assertSame( 1, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) ); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function testTenthEdit() { |
| 57 |
|
| 58 |
$this->deleteEchoData(); |
| 59 |
$user = $this->getMutableTestUser()->getUser(); |
| 60 |
$title = Title::newFromText( 'Help:MWEchoThankYouEditTest_testTenthEdit' ); |
| 61 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
for ( $i = 0; $i < 12; $i++ ) { |
| 68 |
$this->editPage( $page, "this is edit #$i", '', NS_MAIN, $user ); |
| 69 |
} |
| 70 |
$user->clearInstanceCache(); |
| 71 |
|
| 72 |
|
| 73 |
$notificationMapper = new NotificationMapper(); |
| 74 |
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] ); |
| 75 |
$this->assertCount( 2, $notifications ); |
| 76 |
|
| 77 |
|
| 78 |
$notification = reset( $notifications ); |
| 79 |
$this->assertSame( 10, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) ); |
| 80 |
} |
| 81 |
} |