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 {
|
|
|
|
|
2019-10-09 22:57:35 +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
|
|
|
|
|
|
|
$messageCount = 0;
|
2015-10-01 13:48:52 +00:00
|
|
|
$this->assertCount( $messageCount, $this->fetchAllEvents() );
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
// Start a talkpage
|
2019-04-19 18:05:57 +00:00
|
|
|
$content = "== Section 8 ==\n\nblah blah ~~~~\n";
|
2013-05-14 22:22:52 +00:00
|
|
|
$this->editPage( $talkPage, $content, '', NS_USER_TALK );
|
|
|
|
|
|
|
|
// Ensure the proper event was created
|
|
|
|
$events = $this->fetchAllEvents();
|
2020-06-27 10:05:03 +00:00
|
|
|
// +1 is due to 0 index
|
|
|
|
$this->assertCount( 1 + $messageCount, $events, 'After initial edit a single event must exist.' );
|
2013-11-04 17:58:47 +00:00
|
|
|
$row = array_shift( $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
|
|
|
|
$messageCount++;
|
2019-04-19 18:05:57 +00:00
|
|
|
$content .= "More content ~~~~\n";
|
2013-05-14 22:22:52 +00:00
|
|
|
$this->editPage( $talkPage, $content, '', NS_USER_TALK );
|
|
|
|
|
|
|
|
// Ensure another event was created
|
|
|
|
$events = $this->fetchAllEvents();
|
2015-10-01 13:48:52 +00:00
|
|
|
$this->assertCount( 1 + $messageCount, $events );
|
2013-11-04 17:58:47 +00:00
|
|
|
$row = array_shift( $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
|
|
|
|
$messageCount++;
|
2019-04-19 18:05:57 +00:00
|
|
|
$content .= "\n\n== EE ==\n\nhere we go with a new section ~~~~\n";
|
2013-05-14 22:22:52 +00:00
|
|
|
$this->editPage( $talkPage, $content, '', NS_USER_TALK );
|
|
|
|
|
|
|
|
// Ensure this event has the new section title
|
|
|
|
$events = $this->fetchAllEvents();
|
2015-10-01 13:48:52 +00:00
|
|
|
$this->assertCount( 1 + $messageCount, $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' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-09 02:42:55 +00:00
|
|
|
* @return \stdClass[] All non-watchlist 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(), [
|
|
|
|
'event_type != "watchlist-change"'
|
|
|
|
], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] );
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
return iterator_to_array( $res );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|