Debian Codegraph @

extensions/Echo/tests/phpunit/ThankYouEditTest.php

raw symbols SCIP
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 * @group Echo
13 * @group Database
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 * @covers \MediaWiki\Extension\Notifications\Hooks::onPageSaveComplete
33 */
34 public function testFirstEdit() {
35 // setup
36 $this->deleteEchoData();
37 $user = $this->getMutableTestUser()->getUser();
38 $title = Title::newFromText( 'Help:MWEchoThankYouEditTest_testFirstEdit' );
39
40 // action
41 $this->editPage( $title, 'this is my first edit', '', NS_MAIN, $user );
42
43 // assertions
44 $notificationMapper = new NotificationMapper();
45 $notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
46 $this->assertCount( 1, $notifications );
47
48 /** @var Notification $notification */
49 $notification = reset( $notifications );
50 $this->assertSame( 1, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) );
51 }
52
53 /**
54 * @covers \MediaWiki\Extension\Notifications\Hooks::onPageSaveComplete
55 */
56 public function testTenthEdit() {
57 // setup
58 $this->deleteEchoData();
59 $user = $this->getMutableTestUser()->getUser();
60 $title = Title::newFromText( 'Help:MWEchoThankYouEditTest_testTenthEdit' );
61 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
62
63 // action
64 // we could fast-forward the edit-count to speed things up
65 // but this is the only way to make sure duplicate notifications
66 // are not generated
67 for ( $i = 0; $i < 12; $i++ ) {
68 $this->editPage( $page, "this is edit #$i", '', NS_MAIN, $user );
69 }
70 $user->clearInstanceCache();
71
72 // assertions
73 $notificationMapper = new NotificationMapper();
74 $notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
75 $this->assertCount( 2, $notifications );
76
77 /** @var Notification $notification */
78 $notification = reset( $notifications );
79 $this->assertSame( 10, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) );
80 }
81 }