1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Grafizzi\Graph\Tests\AttributeTest: 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\Attribute; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Attribute test case. |
32
|
|
|
*/ |
33
|
|
|
class AttributeTest extends BaseGraphTest { |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
* @var Attribute |
38
|
|
|
*/ |
39
|
|
|
private $Attribute; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Prepares the environment before running a test. |
43
|
|
|
*/ |
44
|
|
|
protected function setUp() : void { |
45
|
|
|
parent::setUpExtended(); |
|
|
|
|
46
|
|
|
$this->Attribute = new Attribute($this->dic, 'label', 'A plain label'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Cleans up the environment after running a test. |
51
|
|
|
*/ |
52
|
|
|
protected function tearDown() : void { |
53
|
|
|
$this->Attribute = null; |
54
|
|
|
parent::tearDown(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Tests Attribute->__construct() |
59
|
|
|
*/ |
60
|
|
|
public function test__construct() { |
61
|
|
|
$this->assertEquals('label', $this->Attribute->getName()); |
62
|
|
|
$this->assertEquals('A plain label', $this->Attribute->getValue()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Tests Attribute->build() |
67
|
|
|
*/ |
68
|
|
|
public function testBuild() { |
69
|
|
|
$ret = $this->Attribute->build($this->Graph->getDirected()); |
70
|
|
|
$this->assertEquals('label="A plain label"', $ret); |
71
|
|
|
|
72
|
|
|
$title = new Attribute($this->dic, 'title', 'Non empty title'); |
73
|
|
|
$ret = $title->build($this->Graph->getDirected()); |
74
|
|
|
$this->assertEquals('title="Non empty title"', $ret, 'Non-empty title built like a normal attribute.'); |
75
|
|
|
|
76
|
|
|
$title = new Attribute($this->dic, 'title', ''); |
77
|
|
|
$ret = $title->build($this->Graph->getDirected()); |
78
|
|
|
$this->assertNull($ret, 'Empty title built as null.'); |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Tests Attribute::getAllowedNames() |
84
|
|
|
*/ |
85
|
|
|
public function testGetAllowedNames() { |
86
|
|
|
$this->assertEmpty(Attribute::getAllowedNames()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Tests Attribute::getDefaultValue() |
91
|
|
|
*/ |
92
|
|
|
public function testGetDefaultValue() { |
93
|
|
|
$name = $this->Attribute->getName(); |
94
|
|
|
$this->assertNull(Attribute::getDefaultValue($name)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Tests Attribute::getType() |
99
|
|
|
*/ |
100
|
|
|
public function testGetType() { |
101
|
|
|
$this->assertEquals('attribute', $this->Attribute->getType()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Tests Attribute->getValue() |
106
|
|
|
*/ |
107
|
|
|
public function testGetValue() { |
108
|
|
|
$this->assertEquals('A plain label', $this->Attribute->getValue()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Tests Attribute->setName() |
113
|
|
|
*/ |
114
|
|
|
public function testSetName() { |
115
|
|
|
$this->Attribute->setName('font'); |
116
|
|
|
$this->assertEquals('font', $this->Attribute->getName()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Tests Attribute->setValue() |
121
|
|
|
* |
122
|
|
|
* @depends testSetName |
123
|
|
|
*/ |
124
|
|
|
public function testSetValue() { |
125
|
|
|
$name = 'Times New Roman'; |
126
|
|
|
$this->Attribute->setValue($name); |
127
|
|
|
$this->assertEquals($name, $this->Attribute->getValue()); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.