-
-
Notifications
You must be signed in to change notification settings - Fork 839
/
pageutils_sectionid.test.php
43 lines (40 loc) · 1.34 KB
/
pageutils_sectionid.test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class sectionid_test extends Dokuwikitest
{
/**
* DataProvider
*
* @return Generator|array
* @see testSectionidsAreUnique
*/
public function provideTestData(){
// Each test case represents a sequence of sections title
return [
[['A', 'A', 'A1']],
[['A', 'A1', 'A']]
];
}
/**
* @dataProvider provideTestData
* @param array $titles
*/
function testSectionidsAreUnique($titles)
{
$check = array();
$alreadyGeneratedIds = array();
foreach($titles as $title){
$newId = sectionID($title, $check);
$this->assertNotContains($newId, $alreadyGeneratedIds, "id $newId has been generated twice. The 2nd time it was for the title $title");
$alreadyGeneratedIds []= $newId;
}
}
/**
* The convention in the code is to pass $check=false when we're not interested in having
* unique sectionID. This test ensures that this type of call is correctly handled
*/
function testSectionIDCanBeCalledWithNonArrayCheck(){
$check = false;
$this->assertEquals("abc", sectionID("abc", $check), "Passing \$check=false shouldn't lead to an error");
$this->assertEquals("abc", sectionID("abc", $check), "Passing \$check=false shouldn't try to deduplicate id");
}
}