mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
Add the test for getAuthors() in JS too
Change-Id: Id7dabc535b6bb688602c0d55fc3696f662cb10c7
This commit is contained in:
parent
515af82061
commit
c64bb6b5b7
|
@ -162,6 +162,7 @@
|
|||
"data/nlwiki-data.json",
|
||||
"data/plwiki-config.json",
|
||||
"data/plwiki-data.json",
|
||||
"cases/authors.json",
|
||||
"cases/comments.json",
|
||||
"cases/transcluded.json",
|
||||
"cases/modified.json",
|
||||
|
|
26
tests/cases/authors.json
Normal file
26
tests/cases/authors.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
[
|
||||
{
|
||||
"thread": {
|
||||
"replies": [
|
||||
{
|
||||
"author": "Eve",
|
||||
"replies": []
|
||||
},
|
||||
{
|
||||
"author": "Bob",
|
||||
"replies": [
|
||||
{
|
||||
"author": "Alice",
|
||||
"replies": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"expected": [
|
||||
"Alice",
|
||||
"Bob",
|
||||
"Eve"
|
||||
]
|
||||
}
|
||||
]
|
|
@ -188,29 +188,10 @@ class CommentParserTest extends CommentTestCase {
|
|||
}
|
||||
|
||||
public function provideAuthors() : array {
|
||||
return [
|
||||
[
|
||||
'thread' => (object)[
|
||||
'replies' => [
|
||||
(object)[
|
||||
'author' => 'Eve',
|
||||
'replies' => []
|
||||
],
|
||||
(object)[
|
||||
'author' => 'Bob',
|
||||
'replies' => [
|
||||
(object)[
|
||||
'author' => 'Alice',
|
||||
'replies' => []
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
]
|
||||
],
|
||||
'expected' => [ 'Alice', 'Bob', 'Eve' ]
|
||||
]
|
||||
];
|
||||
return array_map( function ( $caseItem ) {
|
||||
// PHPUnit requires associative arrays, not stdClass objects
|
||||
return (array)$caseItem;
|
||||
}, self::getJson( '../cases/authors.json', false ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,12 +26,13 @@ abstract class CommentTestCase extends MediaWikiTestCase {
|
|||
* Get parsed JSON from path
|
||||
*
|
||||
* @param string $relativePath
|
||||
* @param bool $assoc See json_decode()
|
||||
* @return array
|
||||
*/
|
||||
protected static function getJson( string $relativePath ) : array {
|
||||
protected static function getJson( string $relativePath, bool $assoc = true ) : array {
|
||||
$json = json_decode(
|
||||
file_get_contents( __DIR__ . '/' . $relativePath ),
|
||||
true
|
||||
$assoc
|
||||
);
|
||||
return $json;
|
||||
}
|
||||
|
|
|
@ -137,3 +137,15 @@ QUnit.test( '#getTranscludedFrom', function ( assert ) {
|
|||
// console.log( JSON.stringify( transcludedFrom, null, 2 ) );
|
||||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( '#getAuthors', function ( assert ) {
|
||||
var cases = require( '../cases/authors.json' );
|
||||
|
||||
cases.forEach( function ( caseItem ) {
|
||||
var authors = parser.getAuthors( caseItem.thread );
|
||||
assert.deepEqual(
|
||||
authors,
|
||||
caseItem.expected
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue