-
Notifications
You must be signed in to change notification settings - Fork 1
/
ComponentTest.php
141 lines (110 loc) · 3.93 KB
/
ComponentTest.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
use Diversity\Component;
use Diversity\Factory;
class ComponentTest extends PHPUnit_Framework_TestCase {
static private $factory;
static public function setUpBeforeClass() {
self::$factory = new Factory(
array(
'archive' => FIXTURES . 'component_archive_1' . DS,
'archive_url' => 'http://foo.bar/'
)
);
}
public function testDependencies() {
$component = self::$factory->get('test_3');
$dependencies = $component->getDependencies();
$this->assertEquals('test_1', $dependencies[0]->name);
}
public function testGetStyles() {
$component = self::$factory->get('test_3');
$styles = $component->getStyles();
$this->assertCount(1, $styles);
$this->assertEquals('http://foo.bar/test_3/0.0.1/main.css', $styles[0]);
}
/**
* @expectedException Diversity\ConfigurationException
* @expectedExceptionMessage Can't get URL without base_url.
*/
public function testGetStylesException() {
$factory = new Factory(array('archive' => FIXTURES . 'component_archive_1' . DS));
$component = $factory->get('test_3');
$styles = $component->getStyles();
$this->fail("Got style urls: " . json_encode($styles));
}
/**
* @expectedException Diversity\ConfigurationException
* @expectedExceptionMessage Can't get URL without base_url.
*/
public function testGetScriptsException() {
$factory = new Factory(array('archive' => FIXTURES . 'component_archive_1' . DS));
$component = $factory->get('test_3');
$styles = $component->getScripts();
$this->fail("Got script urls: " . json_encode($styles));
}
/**
* @expectedException PHPUnit_Framework_Error_Warning
* @expectedExceptionMessage Component needs prerequisite: value
*/
public function testRenderWarningOnPrerequisite() {
$factory = new Factory(
array('archive' => FIXTURES . 'component_archive_3' . DS, 'archive_url' => 'dummy')
);
$component = $factory->get('test1');
$component->render();
}
public function testRenderWithPrerequisite() {
$component = self::$factory->get('test_5');
$rendered = $component->render(
array(
'prerequisites' => array('some_data' => array('title' => 'Some Data'))
)
);
$this->assertEquals(
'Here we can display Some Data. JSON: {"title":"Some Data"}.', $rendered);
}
public function testGetOptionsSchemaFromInline() {
$component = self::$factory->get('test_1:0.1.0');
$schema = $component->getOptionsSchema();
$this->assertEquals("Simple option", $schema->title);
$this->assertEquals("string", $schema->type);
}
public function testGetOptionsSchemaFromFile() {
$component = self::$factory->get('test_3');
$schema = $component->getOptionsSchema();
$this->assertEquals("object", $schema->type);
$this->assertEquals("Your name", $schema->properties->name->title);
}
public function testRenderLanguagePart() {
$component = self::$factory->get('test_6');
$prerequisites = array('localized' => array('sv' => 'svensk sträng', 'en' => 'english string'));
$rendered_en = $component->render(
array(
'language' => 'en',
'prerequisites' => $prerequisites,
)
);
$this->assertEquals('String: "english string"', $rendered_en);
$rendered_sv = $component->render(
array(
'language' => 'sv',
'prerequisites' => $prerequisites,
)
);
$this->assertEquals('String: "svensk sträng"', $rendered_sv);
}
/**
* @expectedException LogicException
* @expectedExceptionMessage base_url must end with a slash
*/
public function testBadBaseUrl() {
$spec = new StdClass;
$spec->name = 'dummy';
$spec->version = '1.2.3';
$component = new Component(
self::$factory, array('spec' => $spec, 'base_url' => 'bad_base_url_with_no_trailing_slash')
);
}
/// @todo Test features:
// When there are several matching versions, you should get the highest.
}