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
|
2013-05-14 22:22:52 +00:00
|
|
|
* @group DataBase
|
|
|
|
* @group medium
|
|
|
|
*/
|
|
|
|
class EchoTalkPageFunctionalTest extends ApiTestCase {
|
|
|
|
|
2018-08-13 07:33:57 +00:00
|
|
|
/**
|
|
|
|
* @var \Wikimedia\Rdbms\IDatabase
|
|
|
|
*/
|
2013-05-14 22:22:52 +00:00
|
|
|
protected $dbr;
|
|
|
|
|
2015-12-14 10:02:34 +00:00
|
|
|
protected function setUp() {
|
2013-05-14 22:22:52 +00:00
|
|
|
parent::setUp();
|
2017-09-24 05:23:47 +00:00
|
|
|
$this->dbr = MWEchoDbFactory::getDB( DB_REPLICA );
|
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'].
|
2014-05-15 08:00:53 +00:00
|
|
|
* @group Broken
|
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
|
|
|
$editor = self::$users['sysop']->getUser()->getName();
|
|
|
|
$talkPage = self::$users['uploader']->getUser()->getName();
|
2013-05-14 22:22:52 +00:00
|
|
|
// A set of messages which will be inserted
|
2016-12-05 18:51:07 +00:00
|
|
|
$messages = [
|
2013-05-14 22:22:52 +00:00
|
|
|
'Moar Cowbell',
|
|
|
|
"I can haz test\n\nplz?", // checks that the parser allows multi-line comments
|
|
|
|
'blah blah',
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
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
|
|
|
|
$content = "== Section 8 ==\n\n" . $this->signedMessage( $editor, $messages[$messageCount] );
|
|
|
|
$this->editPage( $talkPage, $content, '', NS_USER_TALK );
|
|
|
|
|
|
|
|
// Ensure the proper event was created
|
|
|
|
$events = $this->fetchAllEvents();
|
2015-10-01 13:48:52 +00:00
|
|
|
$this->assertCount( 1 + $messageCount, $events, 'After initial edit a single event must exist.' ); // +1 is due to 0 index
|
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++;
|
|
|
|
$content .= $this->signedMessage( $editor, $messages[$messageCount] );
|
|
|
|
$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++;
|
|
|
|
$content .= "\n\n== EE ==\n\n" . $this->signedMessage( $editor, $messages[$messageCount] );
|
|
|
|
$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' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-13 07:25:22 +00:00
|
|
|
* @return \stdClass[] All events in db sorted from oldest to newest
|
2013-05-14 22:22:52 +00:00
|
|
|
*/
|
|
|
|
protected function fetchAllEvents() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$res = $this->dbr->select( 'echo_event', [ '*' ], [], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] );
|
2013-05-14 22:22:52 +00:00
|
|
|
|
|
|
|
return iterator_to_array( $res );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function signedMessage( $name, $content = 'Moar cowbell', $depth = 1 ) {
|
2015-10-01 13:48:52 +00:00
|
|
|
return str_repeat( ':', $depth ) . " $content [[User:$name|$name]] ([[User talk:$name|$name]]) 00:17, 7 May 2013 (UTC)\n";
|
2013-05-14 22:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|