1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Grafizzi\Graph\Tests\escapeTest: a component of the Grafizzi library. |
6
|
|
|
* |
7
|
|
|
* (c) 2012 Frédéric G. MARAND <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Grafizzi is free software: you can redistribute it and/or modify it under the |
10
|
|
|
* terms of the GNU Lesser General Public License as published by the Free |
11
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
12
|
|
|
* later version. |
13
|
|
|
* |
14
|
|
|
* Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY |
15
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
16
|
|
|
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
17
|
|
|
* details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
20
|
|
|
* along with Grafizzi, in the COPYING.LESSER.txt file. If not, see |
21
|
|
|
* <http://www.gnu.org/licenses/> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Grafizzi\Graph\Tests; |
25
|
|
|
|
26
|
|
|
require 'vendor/autoload.php'; |
27
|
|
|
|
28
|
|
|
use Grafizzi\Graph\AbstractNamed; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* escape() test case. |
32
|
|
|
*/ |
33
|
|
|
class escapeTest extends BaseGraphTest { |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Tests escape() |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testEscape() { |
|
|
|
|
39
|
|
|
$testSet = array( |
40
|
|
|
'foo' => 'foo', |
41
|
|
|
'foo bar' => '"foo bar"', |
42
|
|
|
"foo'bar" => '"foo\'bar"', |
43
|
|
|
'foo"bar' => '"foo\"bar"', |
44
|
|
|
// Newline in non-pseudo-HTML mode: escaped |
45
|
|
|
"foo\nbar" => '"foo\nbar"', |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
foreach ($testSet as $in => $expected) { |
49
|
|
|
$actual = AbstractNamed::escape($in); |
50
|
|
|
$this->assertEquals($expected, $actual); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function testEscapePseudoHtml() { |
|
|
|
|
55
|
|
|
$testEscaped = array( |
56
|
|
|
// Test pseudo-HTML label: needs to be <>-wrapped. |
57
|
|
|
'<b>Label</b>' => '<<b>Label</b>>', |
58
|
|
|
// Test non-pseudo-HTML, non-ID label: needs to be dquote-wrapped. |
59
|
|
|
'Non HTML' => '"Non HTML"', |
60
|
|
|
// Test non-pseudo-HTML, ID label: needs not be wrapped. |
61
|
|
|
'nmtoken' => 'nmtoken', |
62
|
|
|
// Newline in pseudo-HTML: not converted |
63
|
|
|
"<b>One\nTwo</b>" => "<<b>One\nTwo</b>>", |
64
|
|
|
); |
65
|
|
|
foreach ($testEscaped as $in => $expected) { |
66
|
|
|
$actual = AbstractNamed::escape($in, true); |
67
|
|
|
$this->assertEquals($expected, $actual); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.