Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7406812
SkinComponentTableOfContentsTest.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
SkinComponentTableOfContentsTest.php
View Options
<?php
use
MediaWiki\Output\OutputPage
;
use
MediaWiki\Skin\SkinComponentTableOfContents
;
use
Wikimedia\Parsoid\Core\SectionMetadata
;
use
Wikimedia\Parsoid\Core\TOCData
;
/**
* @covers \MediaWiki\Skin\SkinComponentTableOfContents
* @group Skin
*/
class
SkinComponentTableOfContentsTest
extends
MediaWikiUnitTestCase
{
private
function
addDefaults
(
array
$sectionData
):
array
{
return
SectionMetadata
::
fromLegacy
(
$sectionData
)->
toLegacy
();
}
public
function
provideGetSectionsData
():
array
{
// byteoffset and fromtitle are redacted from this test.
$SECTION_1
=
[
'toclevel'
=>
1
,
'line'
=>
'Section 1'
,
'anchor'
=>
'section_1'
,
];
$SECTION_1_1
=
[
'toclevel'
=>
2
,
'line'
=>
'Section 1.1'
,
'anchor'
=>
'section_1_1'
,
];
$SECTION_1_2
=
[
'toclevel'
=>
2
,
'line'
=>
'Section 1.2'
,
'anchor'
=>
'section_1_2'
,
];
$SECTION_1_2_1
=
[
'toclevel'
=>
3
,
'line'
=>
'Section 1.2.1'
,
'anchor'
=>
'section_1_2_1'
,
];
$SECTION_1_3
=
[
'toclevel'
=>
2
,
'line'
=>
'Section 1.3'
,
'anchor'
=>
'section_1_3'
,
];
$SECTION_2
=
[
'toclevel'
=>
1
,
'line'
=>
'Section 2'
,
'anchor'
=>
'section_2'
,
];
return
[
[
// isTocEnabled
false
,
// sections data
[],
// expected
[]
],
[
// isTocEnabled
true
,
// sections data
[
$SECTION_1
,
$SECTION_2
],
// expected
[
'number-section-count'
=>
2
,
'array-sections'
=>
[
$this
->
addDefaults
(
$SECTION_1
)
+
[
'array-sections'
=>
[],
'is-top-level-section'
=>
true
,
'is-parent-section'
=>
false
,
],
$this
->
addDefaults
(
$SECTION_2
)
+
[
'array-sections'
=>
[],
'is-top-level-section'
=>
true
,
'is-parent-section'
=>
false
,
]
]
]
],
[
// isTocEnabled
true
,
// sections data
[
$SECTION_1
,
$SECTION_1_1
,
$SECTION_2
,
],
// expected
[
'number-section-count'
=>
3
,
'array-sections'
=>
[
$this
->
addDefaults
(
$SECTION_1
)
+
[
'array-sections'
=>
[
$this
->
addDefaults
(
$SECTION_1_1
)
+
[
'array-sections'
=>
[],
'is-top-level-section'
=>
false
,
'is-parent-section'
=>
false
,
]
],
'is-top-level-section'
=>
true
,
'is-parent-section'
=>
true
,
],
$this
->
addDefaults
(
$SECTION_2
)
+
[
'array-sections'
=>
[],
'is-top-level-section'
=>
true
,
'is-parent-section'
=>
false
,
]
]
]
],
[
// isTocEnabled
true
,
// sections data
[
$SECTION_1
,
$SECTION_1_1
,
$SECTION_1_2
,
$SECTION_1_2_1
,
$SECTION_1_3
,
$SECTION_2
,
],
// expected
[
'number-section-count'
=>
6
,
'array-sections'
=>
[
$this
->
addDefaults
(
$SECTION_1
)
+
[
'array-sections'
=>
[
$this
->
addDefaults
(
$SECTION_1_1
)
+
[
'array-sections'
=>
[],
'is-top-level-section'
=>
false
,
'is-parent-section'
=>
false
,
],
$this
->
addDefaults
(
$SECTION_1_2
)
+
[
'array-sections'
=>
[
$this
->
addDefaults
(
$SECTION_1_2_1
)
+
[
'array-sections'
=>
[],
'is-top-level-section'
=>
false
,
'is-parent-section'
=>
false
,
],
],
'is-top-level-section'
=>
false
,
'is-parent-section'
=>
true
,
],
$this
->
addDefaults
(
$SECTION_1_3
)
+
[
'array-sections'
=>
[],
'is-top-level-section'
=>
false
,
'is-parent-section'
=>
false
,
]
],
'is-top-level-section'
=>
true
,
'is-parent-section'
=>
true
,
],
$this
->
addDefaults
(
$SECTION_2
)
+
[
'array-sections'
=>
[],
'is-top-level-section'
=>
true
,
'is-parent-section'
=>
false
,
]
]
]
]
];
}
/**
* @dataProvider provideGetSectionsData
* @param bool $isTocEnabled
* @param array $sectionsData
* @param array $expected
*/
public
function
testGetTemplateData
(
$isTocEnabled
,
$sectionsData
,
$expected
)
{
// Convert to first class objects
$tocData
=
new
TOCData
;
array_map
(
static
function
(
$s
)
use
(
$tocData
)
{
$tocData
->
addSection
(
SectionMetadata
::
fromLegacy
(
$s
)
);
},
$sectionsData
);
$mockOutput
=
$this
->
createMock
(
OutputPage
::
class
);
$mockOutput
->
method
(
'isTOCEnabled'
)->
willReturn
(
$isTocEnabled
);
$mockOutput
->
method
(
'getTOCData'
)->
willReturn
(
$tocData
);
$skinComponent
=
new
SkinComponentTableOfContents
(
$mockOutput
);
$data
=
$skinComponent
->
getTemplateData
();
$this
->
assertEquals
(
$expected
,
$data
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 20:37 (1 d, 10 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8c/e5/80113a3234cd25444785f3fc3f33
Default Alt Text
SkinComponentTableOfContentsTest.php (4 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment