2013-05-14 22:22:52 +00:00
|
|
|
<?php
|
2015-10-01 13:48:52 +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
|
|
|
|
*/
|
|
|
|
class EchoTalkPageFunctionalTest extends ApiTestCase {
|
|
|
|
|
2021-07-23 21:23:16 +00:00
|
|
|
protected function setUp(): void {
|
2013-05-14 22:22:52 +00:00
|
|
|
parent::setUp();
|
2019-04-19 18:05:57 +00:00
|
|
|
$this->db->delete( 'echo_event', '*' );
|
2013-05-14 22:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and updates a user talk page a few times to ensure proper events are
|
|
|
|
* created. The user performing the edits is self::$users['sysop'].
|
2018-06-14 15:38:07 +00:00
|
|
|
* @covers \EchoDiscussionParser
|
2013-05-14 22:22:52 +00:00
|
|
|
*/
|
|
|
|
public function testAddCommentsToTalkPage() {
|
2015-08-07 16:04:37 +00:00
|
|
|
$talkPage = self::$users['uploader']->getUser()->getName();
|
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,
|
|
|
|
self::$users['sysop']->getUser()
|
|
|
|
);
|
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,
|
|
|
|
self::$users['sysop']->getUser()
|
|
|
|
);
|
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,
|
|
|
|
self::$users['sysop']->getUser()
|
|
|
|
);
|
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() {
|
2019-12-09 02:42:55 +00:00
|
|
|
$res = $this->db->select( 'echo_event', EchoEvent::selectFields(), [
|
2021-03-03 23:33:32 +00:00
|
|
|
'event_type' => 'edit-user-talk',
|
2019-12-09 02:42:55 +00:00
|
|
|
], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] );
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
return iterator_to_array( $res );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|