2013-05-14 22:22:52 +00:00
|
|
|
<?php
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
2024-06-12 18:31:47 +00:00
|
|
|
use MediaWiki\Tests\Api\ApiTestCase;
|
2022-11-02 21:34:17 +00:00
|
|
|
|
2013-05-14 22:22:52 +00:00
|
|
|
/**
|
2014-07-25 20:19:15 +00:00
|
|
|
* @group Echo
|
2018-09-14 19:26:45 +00:00
|
|
|
* @group Database
|
2013-05-14 22:22:52 +00:00
|
|
|
* @group medium
|
|
|
|
*/
|
2023-08-12 19:07:15 +00:00
|
|
|
class TalkPageFunctionalTest extends ApiTestCase {
|
2013-05-14 22:22:52 +00:00
|
|
|
/**
|
|
|
|
* Creates and updates a user talk page a few times to ensure proper events are
|
2023-08-18 13:49:23 +00:00
|
|
|
* created.
|
2022-11-12 07:19:00 +00:00
|
|
|
* @covers \MediaWiki\Extension\Notifications\DiscussionParser
|
2013-05-14 22:22:52 +00:00
|
|
|
*/
|
|
|
|
public function testAddCommentsToTalkPage() {
|
2023-08-18 13:49:23 +00:00
|
|
|
$editor = $this->getTestSysop()->getUser();
|
|
|
|
$talkTitle = $this->getTestSysop()->getUser()->getTalkPage();
|
2023-07-15 20:32:16 +00:00
|
|
|
$talkPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $talkTitle );
|
2013-05-14 22:22:52 +00:00
|
|
|
|
2021-07-21 20:06:25 +00:00
|
|
|
$expectedMessageCount = 0;
|
|
|
|
$this->assertCount( $expectedMessageCount, $this->fetchAllEvents() );
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
// Start a talkpage
|
2021-07-21 20:06:25 +00:00
|
|
|
$expectedMessageCount++;
|
2019-04-19 18:05:57 +00:00
|
|
|
$content = "== Section 8 ==\n\nblah blah ~~~~\n";
|
2020-09-13 07:34:05 +00:00
|
|
|
$this->editPage(
|
|
|
|
$talkPage,
|
|
|
|
$content,
|
|
|
|
'',
|
|
|
|
NS_USER_TALK,
|
2023-08-18 13:49:23 +00:00
|
|
|
$editor
|
2020-09-13 07:34:05 +00:00
|
|
|
);
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
// Ensure the proper event was created
|
|
|
|
$events = $this->fetchAllEvents();
|
2021-07-21 20:06:25 +00:00
|
|
|
$this->assertCount( $expectedMessageCount, $events, 'After initial edit a single event must exist.' );
|
|
|
|
$row = array_pop( $events );
|
2013-05-14 22:22:52 +00:00
|
|
|
$this->assertEquals( 'edit-user-talk', $row->event_type );
|
|
|
|
$this->assertEventSectionTitle( 'Section 8', $row );
|
|
|
|
|
|
|
|
// Add another message to the talk page
|
2021-07-21 20:06:25 +00:00
|
|
|
$expectedMessageCount++;
|
2019-04-19 18:05:57 +00:00
|
|
|
$content .= "More content ~~~~\n";
|
2020-09-13 07:34:05 +00:00
|
|
|
$this->editPage(
|
|
|
|
$talkPage,
|
|
|
|
$content,
|
|
|
|
'',
|
|
|
|
NS_USER_TALK,
|
2023-08-18 13:49:23 +00:00
|
|
|
$editor
|
2020-09-13 07:34:05 +00:00
|
|
|
);
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
// Ensure another event was created
|
|
|
|
$events = $this->fetchAllEvents();
|
2021-07-21 20:06:25 +00:00
|
|
|
$this->assertCount( $expectedMessageCount, $events );
|
|
|
|
$row = array_pop( $events );
|
2013-05-14 22:22:52 +00:00
|
|
|
$this->assertEquals( 'edit-user-talk', $row->event_type );
|
|
|
|
$this->assertEventSectionTitle( 'Section 8', $row );
|
|
|
|
|
|
|
|
// Add a new section and a message within it
|
2021-07-21 20:06:25 +00:00
|
|
|
$expectedMessageCount++;
|
2019-04-19 18:05:57 +00:00
|
|
|
$content .= "\n\n== EE ==\n\nhere we go with a new section ~~~~\n";
|
2020-09-13 07:34:05 +00:00
|
|
|
$this->editPage(
|
|
|
|
$talkPage,
|
|
|
|
$content,
|
|
|
|
'',
|
|
|
|
NS_USER_TALK,
|
2023-08-18 13:49:23 +00:00
|
|
|
$editor
|
2020-09-13 07:34:05 +00:00
|
|
|
);
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
// Ensure this event has the new section title
|
|
|
|
$events = $this->fetchAllEvents();
|
2021-07-21 20:06:25 +00:00
|
|
|
$this->assertCount( $expectedMessageCount, $events );
|
2013-11-04 17:58:47 +00:00
|
|
|
$row = array_pop( $events );
|
2013-05-14 22:22:52 +00:00
|
|
|
$this->assertEquals( 'edit-user-talk', $row->event_type );
|
|
|
|
$this->assertEventSectionTitle( 'EE', $row );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function assertEventSectionTitle( $sectionTitle, $row ) {
|
|
|
|
$this->assertNotNull( $row->event_extra, 'Event must contain extra data.' );
|
|
|
|
$extra = unserialize( $row->event_extra );
|
|
|
|
$this->assertArrayHasKey( 'section-title', $extra, 'Extra data must include a section-title key.' );
|
|
|
|
$this->assertEquals( $sectionTitle, $extra['section-title'], 'Detected section title must match' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-03 23:33:32 +00:00
|
|
|
* @return \stdClass[] All talk page edit events in db sorted from oldest to newest
|
2013-05-14 22:22:52 +00:00
|
|
|
*/
|
|
|
|
protected function fetchAllEvents() {
|
2024-04-27 21:37:18 +00:00
|
|
|
$res = $this->db->newSelectQueryBuilder()
|
|
|
|
->select( Event::selectFields() )
|
|
|
|
->from( 'echo_event' )
|
|
|
|
->where( [
|
2021-03-03 23:33:32 +00:00
|
|
|
'event_type' => 'edit-user-talk',
|
2024-04-27 21:37:18 +00:00
|
|
|
] )
|
|
|
|
->orderBy( 'event_id' )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->fetchResultSet();
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
return iterator_to_array( $res );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|