-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathConfiguratorTest.php
More file actions
184 lines (157 loc) · 4.85 KB
/
ConfiguratorTest.php
File metadata and controls
184 lines (157 loc) · 4.85 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
namespace s9e\TextFormatter\Tests\Plugins\Autoaudio;
use s9e\TextFormatter\Configurator\Items\AttributeFilters\UrlFilter;
use s9e\TextFormatter\Tests\Test;
/**
* @covers s9e\TextFormatter\Plugins\AbstractStaticUrlReplacer\AbstractConfigurator
* @covers s9e\TextFormatter\Plugins\Autoaudio\Configurator
*/
class ConfiguratorTest extends Test
{
/**
* @testdox Automatically creates an "AUDIO" tag with a "src" attribute with a "#url" filter
*/
public function testCreatesTag()
{
$this->configurator->Autoaudio;
$this->assertTrue($this->configurator->tags->exists('AUDIO'));
$tag = $this->configurator->tags->get('AUDIO');
$this->assertTrue($tag->attributes->exists('src'));
$attribute = $tag->attributes->get('src');
$this->assertTrue($attribute->filterChain->contains(new UrlFilter));
}
/**
* @testdox Automatically creates a "filename" attribute
*/
public function testCreatesFilenameAttribute()
{
$this->configurator->Autoaudio;
$tag = $this->configurator->tags->get('AUDIO');
$this->assertTrue($tag->attributes->exists('filename'));
}
/**
* @testdox Does not attempt to create a tag if it already exists
*/
public function testDoesNotCreateTag()
{
$tag = $this->configurator->tags->add('AUDIO');
$this->configurator->plugins->load('Autoaudio');
$this->assertSame($tag, $this->configurator->tags->get('AUDIO'));
}
/**
* @testdox The name of the tag used can be changed through the "tagName" constructor option
*/
public function testCustomTagName()
{
$this->configurator->plugins->load('Autoaudio', ['tagName' => 'FOO']);
$this->assertTrue($this->configurator->tags->exists('FOO'));
}
/**
* @testdox The name of the attribute used can be changed through the "attrName" constructor option
*/
public function testCustomAttrName()
{
$this->configurator->plugins->load('Autoaudio', ['attrName' => 'bar']);
$this->assertTrue($this->configurator->tags['AUDIO']->attributes->exists('bar'));
}
/**
* @testdox Has a quickMatch
*/
public function testConfigQuickMatch()
{
$this->assertArrayHasKey(
'quickMatch',
$this->configurator->plugins->load('Autoaudio')->asConfig()
);
}
/**
* @testdox The config array contains a regexp
*/
public function testConfigRegexp()
{
$this->assertArrayHasKey(
'regexp',
$this->configurator->plugins->load('Autoaudio')->asConfig()
);
}
/**
* @testdox The config array contains the name of the tag
*/
public function testConfigTagName()
{
$config = $this->configurator->plugins->load('Autoaudio')->asConfig();
$this->assertArrayHasKey('tagName', $config);
$this->assertSame('AUDIO', $config['tagName']);
}
/**
* @testdox The config array contains the name of the attribute
*/
public function testConfigAttributeName()
{
$config = $this->configurator->plugins->load('Autoaudio')->asConfig();
$this->assertArrayHasKey('attrName', $config);
$this->assertSame('src', $config['attrName']);
}
/**
* @testdox getTag() returns the tag that is associated with this plugin
*/
public function testGetTag()
{
$plugin = $this->configurator->plugins->load('Autoaudio');
$this->assertSame(
$this->configurator->tags['AUDIO'],
$plugin->getTag()
);
}
/**
* @testdox The JS parser contains both parser files
*/
public function testJSParser()
{
$js = $this->configurator->Autoaudio->getJSParser();
foreach (['AbstractStaticUrlReplacer', 'Autoaudio'] as $pluginName)
{
$filepath = __DIR__ . '/../../../src/Plugins/' . $pluginName . '/Parser.js';
$this->assertStringContainsString(file_get_contents($filepath), $js);
}
}
/**
* @testdox File extensions are configurable
*/
public function testFileExtensions()
{
$this->configurator->Autoaudio->fileExtensions = ['flac', 'wma'];
$this->configurator->Autoaudio->finalize();
$config = $this->configurator->Autoaudio->asConfig();
$this->assertMatchesRegularExpression(
$config['regexp'],
'https://example.org/audio.flac'
);
$this->assertDoesNotMatchRegularExpression(
$config['regexp'],
'https://example.org/audio.mp4'
);
}
/**
* @testdox The default template contains CSS classes for styling
*/
public function testTemplateCSSClasses()
{
$this->configurator->Autoaudio;
$template = (string) $this->configurator->tags['AUDIO']->template;
$this->assertStringContainsString('class="autoaudio"', $template);
$this->assertStringContainsString('class="autoaudio-title"', $template);
$this->assertStringContainsString('class="autoaudio-player"', $template);
}
/**
* @testdox The template can be overridden after configuration
*/
public function testTemplateOverride()
{
$this->configurator->Autoaudio;
$tag = $this->configurator->tags['AUDIO'];
$tag->template = '<audio controls="" class="custom" src="{@src}"/>';
$this->assertStringContainsString('class="custom"', (string) $tag->template);
$this->assertStringNotContainsString('autoaudio', (string) $tag->template);
}
}