Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5978717
DiffParserTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
DiffParserTest.php
View Options
<?php
namespace
MediaWiki\Extension\Notifications\Test\Unit
;
use
MediaWiki\Extension\Notifications\DiscussionParser
;
use
MediaWikiUnitTestCase
;
/**
* @covers \MediaWiki\Extension\Notifications\DiffParser
* @group Echo
*/
class
DiffParserTest
extends
MediaWikiUnitTestCase
{
/**
* @dataProvider provider_getChangeSet
*/
public
function
testGetChangeSet
(
$message
,
array
$expect
,
$leftText
,
$rightText
)
{
$changeSet
=
DiscussionParser
::
getMachineReadableDiff
(
$leftText
,
$rightText
);
unset
(
$changeSet
[
'_info'
]
);
$this
->
assertEquals
(
$expect
,
$changeSet
,
$message
);
}
public
static
function
provider_getChangeSet
()
{
return
[
[
'Duplicate content must generate no changes'
,
// Expected change set
[],
// Left text
"a
\n
b
\n
c"
,
// Right text
"a
\n
b
\n
c"
,
],
[
'Removing blank lines must generate no changes'
,
// Expected change set
[],
// Left text
"a
\n\n
b
\n\n
c"
,
// Right text
"a
\n
b
\n
c
\n
"
,
],
[
'Must generate a single add change with only lines added'
,
// Expected change set
[
self
::
mockAction
(
'add'
,
"foo
\n
bar"
,
1
)
],
// Left
"something"
,
// Right
"foo
\n
bar
\n
something"
,
],
[
'Must generate a single subtract change with only lines subtracted'
,
// Expected change set
[
self
::
mockAction
(
'subtract'
,
"Zomg
\n
HiHiHi"
,
2
)
],
// Left
"dummy
\n
Zomg
\n
HiHiHi"
,
// Right
"dummy"
,
],
[
'Adding content separated by no change must generate multiple changes'
,
// Expected change set
[
self
::
mockAction
(
'add'
,
'b1'
,
3
),
self
::
mockAction
(
'add'
,
"d1
\n
d2"
,
5
,
6
),
],
// Left text
"a
\n
b
\n
c
\n
d
\n
e
\n
f"
,
// Right text
"a
\n
b
\n
b1
\n
c
\n
d
\n
d1
\n
d2
\n
e
\n
f"
,
],
[
'Additon with empty line should be one action'
,
// Expected change set
[
self
::
mockAction
(
'add'
,
"User
\n\n
Signature"
,
1
)
],
// Left text
""
,
// Right text
"User
\n\n
Signature"
,
],
[
'Extra blank lines on the edges must be trimmed'
,
// Expected change set
[
self
::
mockAction
(
'add'
,
"Zomg
\n
HiHiHi"
,
1
)
],
// Left text
""
,
// Right text
"
\n
Zomg
\n
HiHiHi
\n
"
,
],
[
'Extra blank lines inside the content must not be trimmed'
,
// Expected change set
[
self
::
mockAction
(
'add'
,
"
\n
Zomg
\n
HiHiHi
\n
"
,
2
)
],
// Left text
"foo
\n
bar"
,
// Right text
"foo
\n\n
Zomg
\n
HiHiHi
\n\n
bar"
,
],
[
'A blank line replaced with content must be an add'
,
// Expected change set
[
self
::
mockAction
(
'add'
,
'cowbell'
,
1
)
],
// Left Text
""
,
// Right Text
"cowbell"
,
],
[
'A blanked out line must be a subtraction'
,
// Expected change set
[
self
::
mockAction
(
'subtract'
,
'cowbell'
,
1
)
],
// Left text
"cowbell"
,
// Right text
""
,
],
[
'A line with its content replaced must be a change'
,
// Expected change set
[
self
::
mockChange
(
'Its all about the journey'
,
'dummy'
,
1
)
],
// Left text
"Its all about the journey"
,
// Right text
"dummy"
,
],
[
'Changing lines and adding more must result in two changes'
,
// Expected change set
[
self
::
mockChange
(
'Must be in a hurry to finish this thing'
,
'Must be in a hurry'
,
1
),
self
::
mockAction
(
'add'
,
'Finish this thing'
,
2
),
],
// Left text
"Must be in a hurry to finish this thing"
,
// Right text
"Must be in a hurry
\n
Finish this thing"
,
],
[
'Changing multiple lines and adding more must result in two changes'
,
// Expected change set
[
self
::
mockChange
(
"Must not be
\n
in much of a hurry"
,
"Must be
\n
in a hurry"
,
2
),
self
::
mockAction
(
'subtract'
,
"to finish
\n
this thing"
,
4
),
],
// Left text
"abc
\n
Must not be
\n
in much of a hurry
\n
to finish
\n
this thing"
,
// Right text
"abc
\n
Must be
\n
in a hurry"
,
],
[
'Must generate multiple add, change, and subtract actions'
,
// Expected change set
[
self
::
mockChange
(
"abc
\n
Some"
,
"Other
\n
Things"
,
1
),
self
::
mockAction
(
'subtract'
,
"Stuff"
,
3
),
self
::
mockChange
(
"And
\n
Then"
,
"There
\n
Was"
,
6
,
5
),
self
::
mockAction
(
'add'
,
'Fencing'
,
8
,
7
),
],
// Left text
"abc
\n
Some
\n
Stuff
\n
def
\n
ghi
\n
And
\n
Then
\n
jkl
\n
mno"
,
// Right text
"
\n
Other
\n
Things
\n
def
\n
ghi
\n
There
\n
Was
\n
Fencing
\n
jkl
\n
mno"
,
],
];
}
protected
static
function
mockAction
(
$action
,
$content
,
$left
,
$right
=
null
)
{
return
[
'action'
=>
$action
,
'content'
=>
$content
,
'left-pos'
=>
$left
,
'right-pos'
=>
$right
??
$left
,
];
}
public
static
function
mockChange
(
$oldContent
,
$newContent
,
$left
,
$right
=
null
)
{
return
[
'action'
=>
'change'
,
'old_content'
=>
$oldContent
,
'new_content'
=>
$newContent
,
'left-pos'
=>
$left
,
'right-pos'
=>
$right
??
$left
,
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 20:32 (3 d, 21 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b0/15/367f575f9307125b16a415aa29eb
Default Alt Text
DiffParserTest.php (4 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment