2012-07-31 00:29:49 +00:00
|
|
|
<?php
|
|
|
|
|
2014-07-25 20:19:15 +00:00
|
|
|
/**
|
|
|
|
* @group Echo
|
|
|
|
*/
|
2012-07-31 00:29:49 +00:00
|
|
|
class EchoDiscussionParserTest extends MediaWikiTestCase {
|
|
|
|
// TODO test cases for:
|
|
|
|
// - generateEventsForRevision
|
|
|
|
// - stripHeader
|
|
|
|
// - stripIndents
|
|
|
|
// - stripSignature
|
|
|
|
// - getNotifiedUsersForComment
|
|
|
|
|
2013-04-29 23:24:46 +00:00
|
|
|
public function testDiscussionParserAcceptsInternalDiff() {
|
|
|
|
global $wgDiff;
|
|
|
|
|
|
|
|
$origWgDiff = $wgDiff;
|
|
|
|
$wgDiff = '/does/not/exist/or/at/least/we/hope/not';
|
|
|
|
try {
|
|
|
|
$res = EchoDiscussionParser::getMachineReadableDiff(
|
|
|
|
<<<TEXT
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
<<<TEXT
|
|
|
|
line 1
|
|
|
|
line c
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
);
|
|
|
|
} catch ( MWException $e ) {
|
|
|
|
$wgDiff = $origWgDiff;
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
$wgDiff = $origWgDiff;
|
|
|
|
|
|
|
|
// Test failure occurs when MWException is thrown due to parsing failure
|
|
|
|
$this->assertTrue( true );
|
|
|
|
}
|
|
|
|
|
2012-07-31 00:29:49 +00:00
|
|
|
public function testTimestampRegex() {
|
|
|
|
$exemplarTimestamp = self::getExemplarTimestamp();
|
|
|
|
$timestampRegex = EchoDiscussionParser::getTimestampRegex();
|
|
|
|
|
2012-08-31 21:50:46 +00:00
|
|
|
$match = preg_match( '/' . $timestampRegex . '/u', $exemplarTimestamp );
|
2012-07-31 00:29:49 +00:00
|
|
|
$this->assertEquals( 1, $match );
|
|
|
|
}
|
|
|
|
|
2014-01-19 13:41:22 +00:00
|
|
|
public function testGetTimestampPosition() {
|
|
|
|
$line = 'Hello World. '. self::getExemplarTimestamp();
|
|
|
|
$pos = EchoDiscussionParser::getTimestampPosition( $line );
|
|
|
|
$this->assertEquals( 13, $pos );
|
|
|
|
}
|
|
|
|
|
2012-07-31 00:29:49 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider signingDetectionData
|
|
|
|
* FIXME some of the app logic is in the test...
|
|
|
|
*/
|
|
|
|
public function testSigningDetection( $line, $expectedUser ) {
|
2012-08-31 21:50:46 +00:00
|
|
|
if ( !EchoDiscussionParser::isSignedComment( $line ) ) {
|
2012-07-31 00:29:49 +00:00
|
|
|
$this->assertEquals( $expectedUser, false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tsPos = EchoDiscussionParser::getTimestampPosition( $line );
|
|
|
|
$output = EchoDiscussionParser::getUserFromLine( $line, $tsPos );
|
|
|
|
|
|
|
|
if ( $output === false ) {
|
|
|
|
$this->assertEquals( false, $expectedUser );
|
|
|
|
} elseif ( is_array( $expectedUser ) ) {
|
|
|
|
// Sometimes testing for correct user detection,
|
|
|
|
// sometimes testing for offset detection
|
|
|
|
$this->assertEquals( $expectedUser, $output );
|
|
|
|
} else {
|
|
|
|
$this->assertEquals( $expectedUser, $output[1] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function signingDetectionData() {
|
|
|
|
$ts = self::getExemplarTimestamp();
|
|
|
|
return array(
|
|
|
|
// Basic
|
2014-09-29 19:38:01 +00:00
|
|
|
array(
|
|
|
|
"I like this. [[User:Werdna]] ([[User talk:Werdna|talk]]) $ts",
|
|
|
|
array(
|
|
|
|
13,
|
|
|
|
'Werdna'
|
|
|
|
),
|
|
|
|
),
|
2012-07-31 00:29:49 +00:00
|
|
|
// Confounding
|
2014-09-29 19:38:01 +00:00
|
|
|
array(
|
|
|
|
"[[User:Jorm]] is a meanie. --[[User:Werdna|Andrew]] $ts",
|
|
|
|
array(
|
|
|
|
29,
|
|
|
|
"Werdna"
|
|
|
|
),
|
|
|
|
),
|
2012-07-31 00:29:49 +00:00
|
|
|
// Talk page link only
|
2014-09-29 19:38:01 +00:00
|
|
|
array(
|
|
|
|
"[[User:Swalling|Steve]] is the best person I have ever met. --[[User talk:Werdna|Andrew]] $ts",
|
|
|
|
array(
|
|
|
|
62,
|
|
|
|
'Werdna'
|
|
|
|
),
|
|
|
|
),
|
2012-07-31 00:29:49 +00:00
|
|
|
// Anonymous user
|
2014-09-29 19:38:01 +00:00
|
|
|
array(
|
|
|
|
"I am anonymous because I like my IP address. --[[Special:Contributions/127.0.0.1]] $ts",
|
|
|
|
array(
|
|
|
|
47,
|
|
|
|
'127.0.0.1'
|
|
|
|
),
|
|
|
|
),
|
2012-07-31 00:29:49 +00:00
|
|
|
// No signature
|
2014-09-29 19:38:01 +00:00
|
|
|
array(
|
|
|
|
"Well, \nI do think that [[User:Newyorkbrad]] is pretty cool, but what do I know?",
|
|
|
|
false
|
|
|
|
),
|
2012-07-31 00:29:49 +00:00
|
|
|
// Hash symbols in usernames
|
2014-09-29 19:38:01 +00:00
|
|
|
array(
|
|
|
|
"What do you think? [[User talk:We buried our secrets in the garden#top|wbositg]] $ts",
|
|
|
|
array(
|
|
|
|
19,
|
|
|
|
'We buried our secrets in the garden'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// Title that gets normalized different than it is provided in the wikitext
|
|
|
|
array(
|
|
|
|
"Beep boop [[User:I_Heart_Spaces]] ([[User_talk:I_Heart_Spaces]]) $ts",
|
|
|
|
array(
|
|
|
|
10,
|
|
|
|
'I Heart Spaces'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// Accepts ] in the pipe
|
|
|
|
array(
|
|
|
|
"Shake n Bake --[[User:Werdna|wer]dna]] $ts",
|
|
|
|
array(
|
|
|
|
15,
|
|
|
|
'Werdna',
|
|
|
|
),
|
|
|
|
),
|
2012-07-31 00:29:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @dataProvider diffData */
|
|
|
|
public function testDiff( $oldText, $newText, $expected ) {
|
|
|
|
$actual = EchoDiscussionParser::getMachineReadableDiff( $oldText, $newText );
|
|
|
|
unset( $actual['_info'] );
|
|
|
|
unset( $expected['_info'] );
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $actual );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function diffData() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
<<<TEXT
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,<<<TEXT
|
|
|
|
line 1
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
array( array(
|
|
|
|
'action' => 'subtract',
|
|
|
|
'content' => 'line 2',
|
|
|
|
'left-pos' => 2,
|
|
|
|
'right-pos' => 2,
|
|
|
|
) )
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
<<<TEXT
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,<<<TEXT
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
line 2.5
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
array( array(
|
|
|
|
'action' => 'add',
|
|
|
|
'content' => 'line 2.5',
|
|
|
|
'left-pos' => 3,
|
|
|
|
'right-pos' => 3,
|
|
|
|
) )
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
<<<TEXT
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,<<<TEXT
|
|
|
|
line 1
|
|
|
|
line b
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
array( array(
|
|
|
|
'action' => 'change',
|
|
|
|
'old_content' => 'line 2',
|
|
|
|
'new_content' => 'line b',
|
|
|
|
'left-pos' => 2,
|
|
|
|
'right-pos' => 2,
|
|
|
|
) )
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
<<<TEXT
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,<<<TEXT
|
|
|
|
line 1
|
|
|
|
line b
|
|
|
|
line c
|
|
|
|
line d
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'action' => 'change',
|
|
|
|
'old_content' => 'line 2',
|
|
|
|
'new_content' => 'line b',
|
|
|
|
'left-pos' => 2,
|
|
|
|
'right-pos' => 2,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'action' => 'add',
|
|
|
|
'content' => 'line c
|
|
|
|
line d',
|
|
|
|
'left-pos' => 3,
|
|
|
|
'right-pos' => 3,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @dataProvider annotationData */
|
2013-05-19 04:15:45 +00:00
|
|
|
public function testAnnotation( $message, $diff, $user, $expectedAnnotation ) {
|
2012-07-31 00:29:49 +00:00
|
|
|
$actual = EchoDiscussionParser::interpretDiff( $diff, $user );
|
2013-05-19 04:15:45 +00:00
|
|
|
$this->assertEquals( $expectedAnnotation, $actual, $message );
|
2012-07-31 00:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function annotationData() {
|
|
|
|
$ts = self::getExemplarTimestamp();
|
|
|
|
|
|
|
|
return array(
|
2013-05-19 04:15:45 +00:00
|
|
|
|
2012-07-31 00:29:49 +00:00
|
|
|
array(
|
2013-05-19 04:15:45 +00:00
|
|
|
'Must detect added comments',
|
2012-07-31 00:29:49 +00:00
|
|
|
// Diff
|
|
|
|
array(
|
|
|
|
// Action
|
|
|
|
array(
|
|
|
|
'action' => 'add',
|
|
|
|
'content' => ":What do you think? [[User:Werdna]] $ts",
|
|
|
|
'left-pos' => 3,
|
|
|
|
'right-pos' => 3,
|
|
|
|
),
|
|
|
|
'_info' => array(
|
|
|
|
'lhs' => array(
|
|
|
|
'== Section 1 ==',
|
|
|
|
"I do not like you. [[User:Jorm|Jorm]] $ts",
|
|
|
|
),
|
|
|
|
'rhs' => array(
|
|
|
|
'== Section 1 ==',
|
|
|
|
"I do not like you. [[User:Jorm|Jorm]] $ts",
|
|
|
|
":What do you think? [[User:Werdna]] $ts",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// User
|
|
|
|
'Werdna',
|
|
|
|
// Expected annotation
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'type' => 'add-comment',
|
|
|
|
'content' => ":What do you think? [[User:Werdna]] $ts",
|
|
|
|
'full-section' => <<<TEXT
|
|
|
|
== Section 1 ==
|
|
|
|
I do not like you. [[User:Jorm|Jorm]] $ts
|
|
|
|
:What do you think? [[User:Werdna]] $ts
|
|
|
|
TEXT
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2013-05-19 04:15:45 +00:00
|
|
|
|
2012-07-31 00:29:49 +00:00
|
|
|
array(
|
2013-05-19 04:15:45 +00:00
|
|
|
'Full Section must not include the following pre-existing section',
|
2012-07-31 00:29:49 +00:00
|
|
|
// Diff
|
|
|
|
array(
|
|
|
|
// Action
|
|
|
|
array(
|
|
|
|
'action' => 'add',
|
|
|
|
'content' => ":What do you think? [[User:Werdna]] $ts",
|
|
|
|
'left-pos' => 3,
|
|
|
|
'right-pos' => 3,
|
|
|
|
),
|
|
|
|
'_info' => array(
|
|
|
|
'lhs' => array(
|
|
|
|
'== Section 1 ==',
|
|
|
|
"I do not like you. [[User:Jorm|Jorm]] $ts",
|
|
|
|
'== Section 2 ==',
|
|
|
|
"Well well well. [[User:DarTar]] $ts",
|
|
|
|
),
|
|
|
|
'rhs' => array(
|
|
|
|
'== Section 1 ==',
|
|
|
|
"I do not like you. [[User:Jorm|Jorm]] $ts",
|
|
|
|
":What do you think? [[User:Werdna]] $ts",
|
|
|
|
'== Section 2 ==',
|
|
|
|
"Well well well. [[User:DarTar]] $ts",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// User
|
|
|
|
'Werdna',
|
|
|
|
// Expected annotation
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'type' => 'add-comment',
|
|
|
|
'content' => ":What do you think? [[User:Werdna]] $ts",
|
|
|
|
'full-section' => <<<TEXT
|
|
|
|
== Section 1 ==
|
|
|
|
I do not like you. [[User:Jorm|Jorm]] $ts
|
|
|
|
:What do you think? [[User:Werdna]] $ts
|
|
|
|
TEXT
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2013-05-19 04:15:45 +00:00
|
|
|
|
2012-07-31 00:29:49 +00:00
|
|
|
array(
|
2013-05-19 04:15:45 +00:00
|
|
|
'Must detect new-section-with-comment when a new section is added',
|
2012-07-31 00:29:49 +00:00
|
|
|
// Diff
|
|
|
|
array(
|
|
|
|
// Action
|
|
|
|
array(
|
|
|
|
'action' => 'add',
|
|
|
|
'content' => <<<TEXT
|
|
|
|
== Section 1a ==
|
|
|
|
Hmmm? [[User:Jdforrester]] $ts
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
'left-pos' => 4,
|
|
|
|
'right-pos' => 4,
|
|
|
|
),
|
|
|
|
'_info' => array(
|
|
|
|
'lhs' => array(
|
|
|
|
'== Section 1 ==',
|
|
|
|
"I do not like you. [[User:Jorm|Jorm]] $ts",
|
|
|
|
":What do you think? [[User:Werdna]] $ts",
|
|
|
|
'== Section 2 ==',
|
|
|
|
"Well well well. [[User:DarTar]] $ts",
|
|
|
|
),
|
|
|
|
'rhs' => array(
|
|
|
|
'== Section 1 ==',
|
|
|
|
"I do not like you. [[User:Jorm|Jorm]] $ts",
|
|
|
|
":What do you think? [[User:Werdna]] $ts",
|
|
|
|
'== Section 1a ==',
|
|
|
|
'Hmmm? [[User:Jdforrester]] $ts',
|
|
|
|
'== Section 2 ==',
|
|
|
|
"Well well well. [[User:DarTar]] $ts",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// User
|
|
|
|
'Jdforrester',
|
|
|
|
// Expected annotation
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'type' => 'new-section-with-comment',
|
|
|
|
'content' => <<<TEXT
|
|
|
|
== Section 1a ==
|
|
|
|
Hmmm? [[User:Jdforrester]] $ts
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2013-05-19 04:15:45 +00:00
|
|
|
|
|
|
|
array(
|
|
|
|
'Must detect multiple added comments when multiple sections are edited',
|
|
|
|
EchoDiscussionParser::getMachineReadableDiff(
|
|
|
|
<<<TEXT
|
|
|
|
== Section 1 ==
|
|
|
|
I do not like you. [[User:Jorm|Jorm]] $ts
|
|
|
|
:What do you think? [[User:Werdna]] $ts
|
|
|
|
== Section 2 ==
|
|
|
|
Well well well. [[User:DarTar]] $ts
|
|
|
|
== Section 3 ==
|
|
|
|
Hai [[User:Bsitu]] $ts
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
<<<TEXT
|
|
|
|
== Section 1 ==
|
|
|
|
I do not like you. [[User:Jorm|Jorm]] $ts
|
|
|
|
:What do you think? [[User:Werdna]] $ts
|
|
|
|
:New Comment [[User:JarJar]] $ts
|
|
|
|
== Section 2 ==
|
|
|
|
Well well well. [[User:DarTar]] $ts
|
|
|
|
== Section 3 ==
|
|
|
|
Hai [[User:Bsitu]] $ts
|
|
|
|
:Other New Comment [[User:JarJar]] $ts
|
|
|
|
TEXT
|
|
|
|
),
|
|
|
|
// User
|
|
|
|
'JarJar',
|
|
|
|
// Expected annotation
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'type' => 'add-comment',
|
|
|
|
'content' => ":New Comment [[User:JarJar]] $ts",
|
|
|
|
'full-section' => <<<TEXT
|
|
|
|
== Section 1 ==
|
|
|
|
I do not like you. [[User:Jorm|Jorm]] $ts
|
|
|
|
:What do you think? [[User:Werdna]] $ts
|
|
|
|
:New Comment [[User:JarJar]] $ts
|
|
|
|
TEXT
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'type' => 'add-comment',
|
|
|
|
'content' => ":Other New Comment [[User:JarJar]] $ts",
|
|
|
|
'full-section' => <<<TEXT
|
|
|
|
== Section 3 ==
|
|
|
|
Hai [[User:Bsitu]] $ts
|
|
|
|
:Other New Comment [[User:JarJar]] $ts
|
|
|
|
TEXT
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
2012-07-31 00:29:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getExemplarTimestamp() {
|
|
|
|
$title = Title::newMainPage();
|
2012-08-30 16:04:39 +00:00
|
|
|
$user = User::newFromName( 'Test' );
|
2012-07-31 00:29:49 +00:00
|
|
|
$options = new ParserOptions;
|
|
|
|
|
|
|
|
global $wgParser;
|
|
|
|
$exemplarTimestamp =
|
|
|
|
$wgParser->preSaveTransform( '~~~~~', $title, $user, $options );
|
|
|
|
|
|
|
|
return $exemplarTimestamp;
|
|
|
|
}
|
2013-05-17 19:16:46 +00:00
|
|
|
|
2013-07-24 03:50:43 +00:00
|
|
|
static public function provider_detectSectionTitleAndText() {
|
2013-05-17 19:16:46 +00:00
|
|
|
$name = 'TestUser';
|
|
|
|
$comment = self::signedMessage( $name );
|
|
|
|
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'Must detect first sub heading when inserting in the middle of two sub headings',
|
2014-09-29 19:38:01 +00:00
|
|
|
// expected header content
|
2013-05-17 19:16:46 +00:00
|
|
|
'Sub Heading 1',
|
2014-09-29 19:38:01 +00:00
|
|
|
// test content format
|
2013-05-17 19:16:46 +00:00
|
|
|
"
|
|
|
|
== Heading ==
|
|
|
|
$comment
|
|
|
|
|
|
|
|
== Sub Heading 1 ==
|
|
|
|
$comment
|
|
|
|
%s
|
|
|
|
|
|
|
|
== Sub Heading 2 ==
|
|
|
|
$comment
|
|
|
|
",
|
2014-09-29 19:38:01 +00:00
|
|
|
// user signing new comment
|
2013-05-17 19:16:46 +00:00
|
|
|
$name
|
|
|
|
),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Must detect second sub heading when inserting in the end of two sub headings',
|
2014-09-29 19:38:01 +00:00
|
|
|
// expected header content
|
2013-05-17 19:16:46 +00:00
|
|
|
'Sub Heading 2',
|
2014-09-29 19:38:01 +00:00
|
|
|
// test content format
|
2013-05-17 19:16:46 +00:00
|
|
|
"
|
|
|
|
== Heading ==
|
|
|
|
$comment
|
|
|
|
|
|
|
|
== Sub Heading 1 ==
|
|
|
|
$comment
|
|
|
|
|
|
|
|
== Sub Heading 2 ==
|
|
|
|
$comment
|
|
|
|
%s
|
|
|
|
",
|
2014-09-29 19:38:01 +00:00
|
|
|
// user signing new comment
|
2013-05-17 19:16:46 +00:00
|
|
|
$name
|
|
|
|
),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Commenting in multiple sub-headings must result in no section link',
|
2014-09-29 19:38:01 +00:00
|
|
|
// expected header content
|
2013-05-17 19:16:46 +00:00
|
|
|
'',
|
2014-09-29 19:38:01 +00:00
|
|
|
// test content format
|
2013-05-17 19:16:46 +00:00
|
|
|
"
|
|
|
|
== Heading ==
|
|
|
|
$comment
|
|
|
|
|
|
|
|
== Sub Heading 1 ==
|
|
|
|
$comment
|
|
|
|
%s
|
|
|
|
|
|
|
|
== Sub Heading 2 ==
|
|
|
|
$comment
|
|
|
|
%s
|
|
|
|
|
|
|
|
",
|
2014-09-29 19:38:01 +00:00
|
|
|
// user signing new comment
|
2013-05-17 19:16:46 +00:00
|
|
|
$name
|
|
|
|
),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Must accept headings without a space between the = and the section name',
|
2014-09-29 19:38:01 +00:00
|
|
|
// expected header content
|
2013-05-17 19:16:46 +00:00
|
|
|
'Heading',
|
2014-09-29 19:38:01 +00:00
|
|
|
// test content format
|
2013-05-17 19:16:46 +00:00
|
|
|
"
|
|
|
|
==Heading==
|
|
|
|
$comment
|
|
|
|
%s
|
|
|
|
",
|
2014-09-29 19:38:01 +00:00
|
|
|
// user signing new comment
|
2013-05-17 19:16:46 +00:00
|
|
|
$name
|
|
|
|
),
|
|
|
|
|
|
|
|
array(
|
|
|
|
'Must not accept invalid headings split with a return',
|
2014-09-29 19:38:01 +00:00
|
|
|
// expected header content
|
2013-05-17 19:16:46 +00:00
|
|
|
'',
|
2014-09-29 19:38:01 +00:00
|
|
|
// test content format
|
2013-05-17 19:16:46 +00:00
|
|
|
"
|
|
|
|
==Some
|
|
|
|
Heading==
|
|
|
|
$comment
|
|
|
|
%s
|
|
|
|
",
|
2014-09-29 19:38:01 +00:00
|
|
|
// user signing new comment
|
2013-05-17 19:16:46 +00:00
|
|
|
$name
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-24 03:50:43 +00:00
|
|
|
* @dataProvider provider_detectSectionTitleAndText
|
2013-05-17 19:16:46 +00:00
|
|
|
*/
|
2014-09-29 19:38:01 +00:00
|
|
|
public function testDetectSectionTitleAndText( $message, $expect, $format, $name ) {
|
2013-05-17 19:16:46 +00:00
|
|
|
// str_replace because we want to replace multiple instances of '%s' with the same valueA
|
|
|
|
$before = str_replace( '%s', '', $format );
|
|
|
|
$after = str_replace( '%s', self::signedMessage( $name ), $format );
|
|
|
|
|
|
|
|
$diff = EchoDiscussionParser::getMachineReadableDiff( $before, $after );
|
|
|
|
$interp = EchoDiscussionParser::interpretDiff( $diff, $name );
|
2013-07-24 03:50:43 +00:00
|
|
|
|
|
|
|
// There should be a section-text only if there is section-title
|
|
|
|
$expectText = $expect ? self::message( $name ) : '';
|
|
|
|
$this->assertEquals(
|
|
|
|
array( 'section-title' => $expect, 'section-text' => $expectText ),
|
|
|
|
EchoDiscussionParser::detectSectionTitleAndText( $interp, $message )
|
|
|
|
);
|
2013-05-17 19:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static function signedMessage( $name ) {
|
2013-07-24 03:50:43 +00:00
|
|
|
return ": " . self::message() . " [[User:$name|$name]] ([[User talk:$name|talk]]) 00:17, 7 May 2013 (UTC)";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static function message() {
|
|
|
|
return 'foo';
|
2013-05-17 19:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static public function provider_getFullSection() {
|
|
|
|
$tests = array(
|
|
|
|
array(
|
|
|
|
'Extracts full section',
|
|
|
|
// Full document content
|
|
|
|
<<<TEXT
|
|
|
|
==Header 1==
|
|
|
|
foo
|
|
|
|
===Header 2===
|
|
|
|
bar
|
|
|
|
==Header 3==
|
|
|
|
baz
|
|
|
|
TEXT
|
|
|
|
,
|
|
|
|
// Map of Line numbers to expanded section content
|
|
|
|
array(
|
|
|
|
1 => "==Header 1==\nfoo",
|
|
|
|
2 => "==Header 1==\nfoo",
|
|
|
|
3 => "===Header 2===\nbar",
|
|
|
|
4 => "===Header 2===\nbar",
|
|
|
|
5 => "==Header 3==\nbaz",
|
|
|
|
6 => "==Header 3==\nbaz",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Allow for setting an array of line numbers to expand from rather than
|
|
|
|
// just a single line number
|
|
|
|
$retval = array();
|
|
|
|
foreach ( $tests as $test ) {
|
|
|
|
foreach ( $test[2] as $lineNum => $expected ) {
|
|
|
|
$retval[] = array(
|
|
|
|
$test[0],
|
|
|
|
$expected,
|
|
|
|
$test[1],
|
|
|
|
$lineNum,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provider_getFullSection
|
|
|
|
*/
|
|
|
|
public function testGetFullSection( $message, $expect, $lines, $startLineNum ) {
|
|
|
|
$section = EchoDiscussionParser::getFullSection( explode( "\n", $lines ), $startLineNum );
|
|
|
|
$this->assertEquals( $expect, $section, $message );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSectionCount() {
|
|
|
|
$one = "==Zomg==\nfoobar\n";
|
|
|
|
$two = "===SubZomg===\nHi there\n";
|
|
|
|
$three = "==Header==\nOh Hai!\n";
|
|
|
|
|
|
|
|
$this->assertEquals( 1, EchoDiscussionParser::getSectionCount( $one ) );
|
|
|
|
$this->assertEquals( 2, EchoDiscussionParser::getSectionCount( $one . $two ) );
|
|
|
|
$this->assertEquals( 2, EchoDiscussionParser::getSectionCount( $one . $three ) );
|
|
|
|
$this->assertEquals( 3, EchoDiscussionParser::getSectionCount( $one . $two . $three ) );
|
|
|
|
}
|
2012-08-30 16:04:39 +00:00
|
|
|
}
|