From 80704b6e804632f4d7f98cf9d2a8a79945861751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 21 Jul 2021 00:25:21 +0200 Subject: [PATCH] Test cases for interactions with events generated by base Echo Adding test cases in a separate commit to make it easier to review how the test results change after I98fbca8e. * For mentions, the 'mentioned-users' extra parameter is copied to our event (which is then used to avoid duplicate notifications). * For user talk page edit, nothing special happens right now (we use the target page title to avoid duplicate notifications, but this is not apparent from the test case, since page titles are not present). Bug: T281590 Bug: T253082 Change-Id: I153e7735f63f1e2643ed881281d807313cd699c3 --- .../EventDispatcher/no-other-events.json | 1 + .../EventDispatcher/other-events/rev1.txt | 2 + .../other-events/rev2a-other.json | 14 +++++ .../EventDispatcher/other-events/rev2a.json | 28 ++++++++++ .../EventDispatcher/other-events/rev2a.txt | 5 ++ .../other-events/rev2b-other.json | 15 +++++ .../EventDispatcher/other-events/rev2b.json | 31 +++++++++++ .../EventDispatcher/other-events/rev2b.txt | 5 ++ .../other-events/rev2c-other.json | 13 +++++ .../EventDispatcher/other-events/rev2c.json | 29 ++++++++++ .../EventDispatcher/other-events/rev2c.txt | 5 ++ tests/phpunit/EventDispatcherTest.php | 55 ++++++++++++++++++- 12 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 tests/cases/EventDispatcher/no-other-events.json create mode 100644 tests/cases/EventDispatcher/other-events/rev1.txt create mode 100644 tests/cases/EventDispatcher/other-events/rev2a-other.json create mode 100644 tests/cases/EventDispatcher/other-events/rev2a.json create mode 100644 tests/cases/EventDispatcher/other-events/rev2a.txt create mode 100644 tests/cases/EventDispatcher/other-events/rev2b-other.json create mode 100644 tests/cases/EventDispatcher/other-events/rev2b.json create mode 100644 tests/cases/EventDispatcher/other-events/rev2b.txt create mode 100644 tests/cases/EventDispatcher/other-events/rev2c-other.json create mode 100644 tests/cases/EventDispatcher/other-events/rev2c.json create mode 100644 tests/cases/EventDispatcher/other-events/rev2c.txt diff --git a/tests/cases/EventDispatcher/no-other-events.json b/tests/cases/EventDispatcher/no-other-events.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/tests/cases/EventDispatcher/no-other-events.json @@ -0,0 +1 @@ +[] diff --git a/tests/cases/EventDispatcher/other-events/rev1.txt b/tests/cases/EventDispatcher/other-events/rev1.txt new file mode 100644 index 000000000..b5aa3edec --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev1.txt @@ -0,0 +1,2 @@ +== A == +B. --[[User:X]] 00:01, 1 January 2020 (UTC) diff --git a/tests/cases/EventDispatcher/other-events/rev2a-other.json b/tests/cases/EventDispatcher/other-events/rev2a-other.json new file mode 100644 index 000000000..c4f4eeee7 --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2a-other.json @@ -0,0 +1,14 @@ +[ + { + "type": "edit-user-talk", + "title": {}, + "extra": { + "revid": 0, + "minoredit": false, + "section-title": "C", + "section-text": "D.", + "target-page": 0 + }, + "agent": {} + } +] diff --git a/tests/cases/EventDispatcher/other-events/rev2a.json b/tests/cases/EventDispatcher/other-events/rev2a.json new file mode 100644 index 000000000..eb3d44d84 --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2a.json @@ -0,0 +1,28 @@ +[ + { + "type": "edit-user-talk", + "title": [], + "extra": { + "revid": 0, + "minoredit": false, + "section-title": "C", + "section-text": "D.", + "target-page": 0 + }, + "agent": [] + }, + { + "type": "dt-subscribed-new-comment", + "title": {}, + "extra": { + "subscribed-comment-name": "h-Y-2020-01-01T00:02:00.000Z", + "comment-id": "c-Y-2020-01-01T00:02:00.000Z-C", + "comment-name": "c-Y-2020-01-01T00:02:00.000Z", + "content": "D.", + "section-title": "C", + "revid": null, + "mentioned-users": [] + }, + "agent": {} + } +] diff --git a/tests/cases/EventDispatcher/other-events/rev2a.txt b/tests/cases/EventDispatcher/other-events/rev2a.txt new file mode 100644 index 000000000..a514360b9 --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2a.txt @@ -0,0 +1,5 @@ +== A == +B. --[[User:X]] 00:01, 1 January 2020 (UTC) + +== C == +D. --[[User:Y]] 00:02, 1 January 2020 (UTC) diff --git a/tests/cases/EventDispatcher/other-events/rev2b-other.json b/tests/cases/EventDispatcher/other-events/rev2b-other.json new file mode 100644 index 000000000..a085faee4 --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2b-other.json @@ -0,0 +1,15 @@ +[ + { + "type": "mention", + "title": {}, + "extra": { + "content": "@User:Z D.", + "section-title": "C", + "revid": 0, + "mentioned-users": { + "1": 1 + } + }, + "agent": {} + } +] diff --git a/tests/cases/EventDispatcher/other-events/rev2b.json b/tests/cases/EventDispatcher/other-events/rev2b.json new file mode 100644 index 000000000..dd766e0a2 --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2b.json @@ -0,0 +1,31 @@ +[ + { + "type": "mention", + "title": [], + "extra": { + "content": "@User:Z D.", + "section-title": "C", + "revid": 0, + "mentioned-users": { + "1": 1 + } + }, + "agent": [] + }, + { + "type": "dt-subscribed-new-comment", + "title": {}, + "extra": { + "subscribed-comment-name": "h-Y-2020-01-01T00:02:00.000Z", + "comment-id": "c-Y-2020-01-01T00:02:00.000Z-C", + "comment-name": "c-Y-2020-01-01T00:02:00.000Z", + "content": "@User:Z D.", + "section-title": "C", + "revid": null, + "mentioned-users": { + "1": 1 + } + }, + "agent": {} + } +] diff --git a/tests/cases/EventDispatcher/other-events/rev2b.txt b/tests/cases/EventDispatcher/other-events/rev2b.txt new file mode 100644 index 000000000..76f1f7171 --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2b.txt @@ -0,0 +1,5 @@ +== A == +B. --[[User:X]] 00:01, 1 January 2020 (UTC) + +== C == +@[[User:Z]] D. --[[User:Y]] 00:02, 1 January 2020 (UTC) diff --git a/tests/cases/EventDispatcher/other-events/rev2c-other.json b/tests/cases/EventDispatcher/other-events/rev2c-other.json new file mode 100644 index 000000000..b6fcba45b --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2c-other.json @@ -0,0 +1,13 @@ +[ + { + "type": "mention-summary", + "title": {}, + "extra": { + "revid": 0, + "mentioned-users": { + "1": 1 + } + }, + "agent": {} + } +] diff --git a/tests/cases/EventDispatcher/other-events/rev2c.json b/tests/cases/EventDispatcher/other-events/rev2c.json new file mode 100644 index 000000000..e43a5d1e0 --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2c.json @@ -0,0 +1,29 @@ +[ + { + "type": "mention-summary", + "title": [], + "extra": { + "revid": 0, + "mentioned-users": { + "1": 1 + } + }, + "agent": [] + }, + { + "type": "dt-subscribed-new-comment", + "title": {}, + "extra": { + "subscribed-comment-name": "h-Y-2020-01-01T00:02:00.000Z", + "comment-id": "c-Y-2020-01-01T00:02:00.000Z-C", + "comment-name": "c-Y-2020-01-01T00:02:00.000Z", + "content": "D.", + "section-title": "C", + "revid": null, + "mentioned-users": { + "1": 1 + } + }, + "agent": {} + } +] diff --git a/tests/cases/EventDispatcher/other-events/rev2c.txt b/tests/cases/EventDispatcher/other-events/rev2c.txt new file mode 100644 index 000000000..a514360b9 --- /dev/null +++ b/tests/cases/EventDispatcher/other-events/rev2c.txt @@ -0,0 +1,5 @@ +== A == +B. --[[User:X]] 00:01, 1 January 2020 (UTC) + +== C == +D. --[[User:Y]] 00:02, 1 January 2020 (UTC) diff --git a/tests/phpunit/EventDispatcherTest.php b/tests/phpunit/EventDispatcherTest.php index b2268ff71..65f54be60 100644 --- a/tests/phpunit/EventDispatcherTest.php +++ b/tests/phpunit/EventDispatcherTest.php @@ -19,7 +19,7 @@ class EventDispatcherTest extends IntegrationTestCase { * @covers ::generateEventsFromParsers */ public function testGenerateEventsFromParsers( - string $rev1, string $rev2, string $authorUsername, string $expected + string $rev1, string $rev2, string $authorUsername, string $other, string $expected ): void { $wikitext1 = self::getText( $rev1 ); $wikitext2 = self::getText( $rev2 ); @@ -39,7 +39,7 @@ class EventDispatcherTest extends IntegrationTestCase { $parser1 = self::createParser( $body1, $data ); $parser2 = self::createParser( $body2, $data ); - $events = []; + $events = self::getJson( $other, true ); $fakeUser = new UserIdentityValue( 0, $authorUsername ); $fakeTitle = new PageIdentityValue( 0, NS_TALK, __CLASS__, PageIdentityValue::LOCAL ); @@ -67,24 +67,28 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/simple/rev1.txt', 'cases/EventDispatcher/simple/rev2.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/simple/rev2.json', ], [ 'cases/EventDispatcher/simple/rev2.txt', 'cases/EventDispatcher/simple/rev3.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/simple/rev3.json', ], [ 'cases/EventDispatcher/simple/rev3.txt', 'cases/EventDispatcher/simple/rev4.txt', 'Y', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/simple/rev4.json', ], [ 'cases/EventDispatcher/simple/rev4.txt', 'cases/EventDispatcher/simple/rev5.txt', 'X', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/simple/rev5.json', ], // Adding a new section with heading and a top-level comment. @@ -92,6 +96,7 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/newsection/rev1.txt', 'cases/EventDispatcher/newsection/rev2.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/newsection/rev2.json', ], // Adding multiple replies in one edit. @@ -99,6 +104,7 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/multiple/rev1.txt', 'cases/EventDispatcher/multiple/rev2.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/multiple/rev2.json', ], // Adding comments in section 0 (before first heading). These do not generate notifications, @@ -107,12 +113,14 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/section0/rev1.txt', 'cases/EventDispatcher/section0/rev2.txt', 'X', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/section0/rev2.json', ], [ 'cases/EventDispatcher/section0/rev2.txt', 'cases/EventDispatcher/section0/rev3.txt', 'Y', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/section0/rev3.json', ], // Adding a comment in a previously empty section. @@ -120,6 +128,7 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/emptysection/rev1.txt', 'cases/EventDispatcher/emptysection/rev2.txt', 'Y', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/emptysection/rev2.json', ], // Adding comments in sub-sections, where the parent section has no comments (except in @@ -129,12 +138,14 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/subsection-empty/rev1.txt', 'cases/EventDispatcher/subsection-empty/rev2.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/subsection-empty/rev2.json', ], [ 'cases/EventDispatcher/subsection-empty/rev2.txt', 'cases/EventDispatcher/subsection-empty/rev3.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/subsection-empty/rev3.json', ], // Adding comments in sub-sections, where the parent section also has comments. @@ -142,18 +153,21 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/subsection/rev1.txt', 'cases/EventDispatcher/subsection/rev2.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/subsection/rev2.json', ], [ 'cases/EventDispatcher/subsection/rev2.txt', 'cases/EventDispatcher/subsection/rev3.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/subsection/rev3.json', ], [ 'cases/EventDispatcher/subsection/rev3.txt', 'cases/EventDispatcher/subsection/rev4.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/subsection/rev4.json', ], // Edits that do not add comments, and do not generate notifications. @@ -162,6 +176,7 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/notcomments/rev1.txt', 'cases/EventDispatcher/notcomments/rev2.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/notcomments/rev2.json', ], [ @@ -169,6 +184,7 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/notcomments/rev2.txt', 'cases/EventDispatcher/notcomments/rev3.txt', 'X', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/notcomments/rev3.json', ], [ @@ -176,6 +192,7 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/notcomments/rev3.txt', 'cases/EventDispatcher/notcomments/rev4.txt', 'X', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/notcomments/rev4.json', ], // Multiple edits within a minute adding comments by the same user. @@ -184,56 +201,90 @@ class EventDispatcherTest extends IntegrationTestCase { 'cases/EventDispatcher/sametime/rev1.txt', 'cases/EventDispatcher/sametime/rev2.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev2.json', ], [ 'cases/EventDispatcher/sametime/rev2.txt', 'cases/EventDispatcher/sametime/rev3-case1.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev3-case1.json', ], [ 'cases/EventDispatcher/sametime/rev2.txt', 'cases/EventDispatcher/sametime/rev3-case2.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev3-case2.json', ], [ 'cases/EventDispatcher/sametime/rev2.txt', 'cases/EventDispatcher/sametime/rev3-case3.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev3-case3.json', ], [ 'cases/EventDispatcher/sametime/rev2.txt', 'cases/EventDispatcher/sametime/rev3-case4.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev3-case4.json', ], [ 'cases/EventDispatcher/sametime/rev2.txt', 'cases/EventDispatcher/sametime/rev3-case5.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev3-case5.json', ], [ 'cases/EventDispatcher/sametime/rev1b.txt', 'cases/EventDispatcher/sametime/rev2b.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev2b.json', ], [ 'cases/EventDispatcher/sametime/rev2b.txt', 'cases/EventDispatcher/sametime/rev3b-case6.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev3b-case6.json', ], [ 'cases/EventDispatcher/sametime/rev2b.txt', 'cases/EventDispatcher/sametime/rev3b-case7.txt', 'Z', + '../cases/EventDispatcher/no-other-events.json', '../cases/EventDispatcher/sametime/rev3b-case7.json', ], + // Interactions with events generated by base Echo. + [ + // User talk page edit + 'cases/EventDispatcher/other-events/rev1.txt', + 'cases/EventDispatcher/other-events/rev2a.txt', + 'Y', + '../cases/EventDispatcher/other-events/rev2a-other.json', + '../cases/EventDispatcher/other-events/rev2a.json', + ], + [ + // Mention + 'cases/EventDispatcher/other-events/rev1.txt', + 'cases/EventDispatcher/other-events/rev2b.txt', + 'Y', + '../cases/EventDispatcher/other-events/rev2b-other.json', + '../cases/EventDispatcher/other-events/rev2b.json', + ], + [ + // Mention in edit summary + 'cases/EventDispatcher/other-events/rev1.txt', + 'cases/EventDispatcher/other-events/rev2c.txt', + 'Y', + '../cases/EventDispatcher/other-events/rev2c-other.json', + '../cases/EventDispatcher/other-events/rev2c.json', + ], ]; }