-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilsCustomOptionTest.php
More file actions
367 lines (275 loc) · 18.4 KB
/
UtilsCustomOptionTest.php
File metadata and controls
367 lines (275 loc) · 18.4 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
declare(strict_types=1);
namespace Contentstack\Tests\Utils;
require_once __DIR__ . '/Helpers/Utility.php';
require_once __DIR__ . '/Mock/EmbedObjectMock.php';
require_once __DIR__ . '/Mock/Constants.php';
require_once __DIR__ . '/Mock/CustomOptionMock.php';
use Contentstack\Utils\Utils;
use Contentstack\Utils\Model\Option;
use Contentstack\Utils\Enum\EmbedItemType;
use PHPUnit\Framework\TestCase;
class UtilsCustomOptionTest extends TestCase
{
public static $defaultRender;
public function setUp(): void{
UtilsCustomOptionTest::$defaultRender = new CustomOptionMock(EmbedObjectMock::embeddedModel(''));
}
public function testRenderBlankString(): void
{
$embedString = Blank;
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString)));
$this->assertEquals($embedString, trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testRenderArrayBlankString(): void
{
$sss = Utils::renderContents([Blank], new CustomOptionMock(EmbedObjectMock::embeddedModel([Blank])));
$this->assertEquals([Blank], $sss);
}
public function testRenderString(): void
{
$embedString = "<h1>TEST </h2>";
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString)));
$this->assertEquals('<h1>TEST </h2>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testRenderArrayString(): void
{
$embedString = "<h1>TEST </h2>";
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString])));
$this->assertEquals(['<h1>TEST </h2>'], $sss);
}
public function testNonHtmlString(): void
{
$embedString = NoHTML;
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString)));
$this->assertEquals($embedString, trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testNonHtmlArrayString(): void
{
$embedString = NoHTML;
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString])));
$this->assertEquals([$embedString], $sss);
}
public function testHtmlString(): void
{
$embedString = SimpleHTML;
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString)));
$this->assertEquals($embedString, trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testHtmlArrayString(): void
{
$embedString = SimpleHTML;
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString])));
$this->assertEquals([$embedString], $sss);
}
public function testEmbeddedBlankItems(): void
{
$embedString = UnexpectedClose;
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedBlankItems($embedString)));
$this->assertEquals('', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testEmbeddedBlankItemsArray(): void
{
$embedString = UnexpectedClose;
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedBlankItems([$embedString])));
$this->assertEquals([''], $sss);
}
public function testUnexpectedClose(): void
{
$embedString = UnexpectedClose;
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString)));
$this->assertEquals('<span class="embedded-asset" type="asset" data-sys-entry-uid="uid" data-sys-content-type-uid="data-sys-content-type-uid" style="display:inline;" sys-style-type="inline" >uid</span>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testUnexpectedCloseArray(): void
{
$embedString = UnexpectedClose;
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString])));
$this->assertEquals(['<span class="embedded-asset" type="asset" data-sys-entry-uid="uid" data-sys-content-type-uid="data-sys-content-type-uid" style="display:inline;" sys-style-type="inline" >uid</span>'], $sss);
}
public function testNoChildmodel(): void
{
$embedString = NoChildNode;
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString)));
$this->assertEquals('<span class="embedded-asset" type="asset" data-sys-entry-uid="uid" data-sys-content-type-uid="data-sys-content-type-uid" style="display:inline;" sys-style-type="inline" >uid</span>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testNoChildmodelArray(): void
{
$embedString = NoChildNode;
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString])));
$this->assertEquals(['<span class="embedded-asset" type="asset" data-sys-entry-uid="uid" data-sys-content-type-uid="data-sys-content-type-uid" style="display:inline;" sys-style-type="inline" >uid</span>
'], $sss);
}
public function testAssetDisplay(): void
{
$embedString = AssetDisplay;
$sss = Utils::renderContent($embedString, UtilsCustomOptionTest::$defaultRender);
$this->assertEquals('', trim(preg_replace('/\s\s+/', '', $sss)));
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString, '', 'blt8d49bb742bcf2c83')));
$this->assertEquals('<img class="embedded-asset" type="asset" data-sys-asset-uid="blt8d49bb742bcf2c83" style="display:inline;" sys-style-type="display"/>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testAssetDisplayArray(): void
{
$embedString = AssetDisplay;
$sss = Utils::renderContents([$embedString], UtilsCustomOptionTest::$defaultRender);
$this->assertEquals(['
'], $sss);
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString], '', 'blt8d49bb742bcf2c83')));
$this->assertEquals(['<img class="embedded-asset" type="asset" data-sys-asset-uid="blt8d49bb742bcf2c83" style="display:inline;" sys-style-type="display" />
'], $sss);
}
public function testEntryBlock(): void
{
$embedString = EntryBlock;
$sss = Utils::renderContent($embedString, UtilsCustomOptionTest::$defaultRender);
$this->assertEquals('', trim(preg_replace('/\s\s+/', '', $sss)));
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString, 'blt55f6d8cbd7e03a1f')));
$this->assertEquals('<div class="embedded-entry block-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" sys-style-type="block" ><p>blt55f6d8cbd7e03a1f</p><p>Content type: <span>contentTypeUid</span></p></div>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testEntryBlockArray(): void
{
$embedString = EntryBlock;
$sss = Utils::renderContents([$embedString], UtilsCustomOptionTest::$defaultRender);
$this->assertEquals(['
'], $sss);
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString], 'blt55f6d8cbd7e03a1f')));
$this->assertEquals(['<div class="embedded-entry block-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" sys-style-type="block" ><p>blt55f6d8cbd7e03a1f</p><p>Content type: <span>contentTypeUid</span></p></div>
'], $sss);
}
public function testEntryInline(): void
{
$embedString = EntryInline;
$sss = Utils::renderContent($embedString, UtilsCustomOptionTest::$defaultRender);
$this->assertEquals('', trim(preg_replace('/\s\s+/', '', $sss)));
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString, 'blt55f6d8cbd7e03a1f')));
$this->assertEquals('<span class="embedded-entry inline-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="inline" >blt55f6d8cbd7e03a1f</span>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testEntryInlineArray(): void
{
$embedString = EntryInline;
$sss = Utils::renderContents([$embedString], UtilsCustomOptionTest::$defaultRender);
$this->assertEquals(['
'], $sss);
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString], 'blt55f6d8cbd7e03a1f')));
$this->assertEquals(['<span class="embedded-entry inline-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="inline" >blt55f6d8cbd7e03a1f</span>
'], $sss);
}
public function testEntryLink(): void
{
$embedString = EntryLink;
$sss = Utils::renderContent($embedString, UtilsCustomOptionTest::$defaultRender);
$this->assertEquals('', trim(preg_replace('/\s\s+/', '', $sss)));
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString, 'blt55f6d8cbd7e03a1f')));
$this->assertEquals('<a class="embedded-entry link-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="link" >
{{title}}
</a>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testEntryLinkArray(): void
{
$embedString = EntryLink;
$sss = Utils::renderContents([$embedString], UtilsCustomOptionTest::$defaultRender);
$this->assertEquals(['
'], $sss);
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString], 'blt55f6d8cbd7e03a1f')));
$this->assertEquals(['<a class="embedded-entry link-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="link" >
{{title}}
</a>
'], $sss);
}
public function testAsset(): void
{
$embedString = AssetEmbed;
$sss = Utils::renderContent($embedString, UtilsCustomOptionTest::$defaultRender);
$this->assertEquals('<p></p>
<p></p>', trim(preg_replace('/\s\s+/', '', $sss)));
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString, '', 'blt8d49bb742bcf2c83')));
$this->assertEquals('<img class="embedded-asset" data-sys-asset-filelink="https://images.contentstack.com/v3/assets/blt77263d300aee3e6b/blt8d49bb742bcf2c83/5f744bfcb3d3d20813386c10/clitud.jpeg" data-sys-asset-uid="blt8d49bb742bcf2c83" data-sys-asset-filename="Cuvier-67_Autruche_d_Afrique.jpg" data-sys-asset-contenttype="image/jpeg" data-sys-asset-alt="Cuvier-67_Autruche_d_Afrique.jpg" data-sys-asset-caption="somecaption" data-sys-asset-link="http://abc.com" data-sys-asset-position="center" data-sys-asset-isnewtab="true" type="asset" sys-style-type="display"/>
<p></p>
<p></p>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testAssetArray(): void
{
$embedString = AssetEmbed;
$sss = Utils::renderContents([$embedString], UtilsCustomOptionTest::$defaultRender);
$this->assertEquals(['
<p></p>
<p></p>
'], $sss);
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString], '', 'blt8d49bb742bcf2c83')));
$this->assertEquals(['<img class="embedded-asset" data-sys-asset-filelink="https://images.contentstack.com/v3/assets/blt77263d300aee3e6b/blt8d49bb742bcf2c83/5f744bfcb3d3d20813386c10/clitud.jpeg" data-sys-asset-uid="blt8d49bb742bcf2c83" data-sys-asset-filename="Cuvier-67_Autruche_d_Afrique.jpg" data-sys-asset-contenttype="image/jpeg" data-sys-asset-alt="Cuvier-67_Autruche_d_Afrique.jpg" data-sys-asset-caption="somecaption" data-sys-asset-link="http://abc.com" data-sys-asset-position="center" data-sys-asset-isnewtab="true" type="asset" sys-style-type="display" />
<p></p>
<p></p>
'], $sss);
}
public function testEntryBlockLink(): void
{
$embedString = EntryBlock.EntryLink;
$sss = Utils::renderContent($embedString, UtilsCustomOptionTest::$defaultRender);
$this->assertEquals('', trim(preg_replace('/\s\s+/', '', $sss)));
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString, 'blt55f6d8cbd7e03a1f')));
$this->assertEquals('<div class="embedded-entry block-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" sys-style-type="block" ><p>blt55f6d8cbd7e03a1f</p><p>Content type: <span>contentTypeUid</span></p></div><a class="embedded-entry link-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="link" >
{{title}}
</a>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testEntryBlockLinkArray(): void
{
$embedString = EntryBlock.EntryLink;
$sss = Utils::renderContents([$embedString], UtilsCustomOptionTest::$defaultRender);
$this->assertEquals(['
'], $sss);
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString], 'blt55f6d8cbd7e03a1f')));
$this->assertEquals(['<div class="embedded-entry block-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" sys-style-type="block" ><p>blt55f6d8cbd7e03a1f</p><p>Content type: <span>contentTypeUid</span></p></div>
<a class="embedded-entry link-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="link" >
{{title}}
</a>
'], $sss);
}
public function testEntryBlockLinkInline(): void
{
$embedString = EntryBlock.EntryLink.EntryInline;
$sss = Utils::renderContent($embedString, UtilsCustomOptionTest::$defaultRender);
$this->assertEquals('', trim(preg_replace('/\s\s+/', '', $sss)));
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString, 'blt55f6d8cbd7e03a1f')));
$this->assertEquals('<div class="embedded-entry block-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" sys-style-type="block" ><p>blt55f6d8cbd7e03a1f</p><p>Content type: <span>contentTypeUid</span></p></div><a class="embedded-entry link-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="link" >
{{title}}
</a><span class="embedded-entry inline-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="inline" >blt55f6d8cbd7e03a1f</span>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testEntryBlockLinkInlineArray(): void
{
$embedString = EntryBlock.EntryLink.EntryInline;
$sss = Utils::renderContents([$embedString], UtilsCustomOptionTest::$defaultRender);
$this->assertEquals(['
'], $sss);
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString], 'blt55f6d8cbd7e03a1f')));
$this->assertEquals(['<div class="embedded-entry block-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" sys-style-type="block" ><p>blt55f6d8cbd7e03a1f</p><p>Content type: <span>contentTypeUid</span></p></div>
<a class="embedded-entry link-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="link" >
{{title}}
</a>
<span class="embedded-entry inline-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="inline" >blt55f6d8cbd7e03a1f</span>
'], $sss);
}
public function testAllEmbedStyles(): void
{
$embedString = AssetDisplay.EntryBlock.EntryLink.EntryInline;
$sss = Utils::renderContent($embedString, UtilsCustomOptionTest::$defaultRender);
$this->assertEquals('', trim(preg_replace('/\s\s+/', '', $sss)));
$sss = Utils::renderContent($embedString, new CustomOptionMock(EmbedObjectMock::embeddedModel($embedString, 'blt55f6d8cbd7e03a1f', )));
$this->assertEquals('<div class="embedded-entry block-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" sys-style-type="block" ><p>blt55f6d8cbd7e03a1f</p><p>Content type: <span>contentTypeUid</span></p></div><a class="embedded-entry link-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="link" >
{{title}}
</a><span class="embedded-entry inline-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="inline" >blt55f6d8cbd7e03a1f</span>', trim(preg_replace('/\s\s+/', '', $sss)));
}
public function testAllEmbedStylesArray(): void
{
$embedString = AssetDisplay.EntryBlock.EntryLink.EntryInline;
$sss = Utils::renderContents([$embedString], UtilsCustomOptionTest::$defaultRender);
$this->assertEquals(['
'], $sss);
$sss = Utils::renderContents([$embedString], new CustomOptionMock(EmbedObjectMock::embeddedModel([$embedString], 'blt55f6d8cbd7e03a1f')));
$this->assertEquals(['
<div class="embedded-entry block-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" sys-style-type="block" ><p>blt55f6d8cbd7e03a1f</p><p>Content type: <span>contentTypeUid</span></p></div>
<a class="embedded-entry link-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="link" >
{{title}}
</a>
<span class="embedded-entry inline-entry" type="entry" data-sys-entry-uid="blt55f6d8cbd7e03a1f" data-sys-content-type-uid="article" style="display:inline;" sys-style-type="inline" >blt55f6d8cbd7e03a1f</span>
'], $sss);
}
}