-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomOptionTest.php
More file actions
106 lines (84 loc) · 6.4 KB
/
CustomOptionTest.php
File metadata and controls
106 lines (84 loc) · 6.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
<?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/CustomOptionMock.php';
use Contentstack\Utils\Utils;
use Contentstack\Utils\Enum\EmbedItemType;
use Contentstack\Utils\Enum\StyleType;
use Contentstack\Utils\Model\Metadata;
use Contentstack\Utils\Model\Option;
use PHPUnit\Framework\TestCase;
class CustomOptionTest extends TestCase
{
public static $customeRender;
public static $embeddedEntry;
public static $embeddedContentType;
public static $embeddedAsset;
public static $text = "Text To set Link";
public function getMetadata($itemType, $styleType, $linkText = null)
{
$html = "<test type={$itemType} sys-style-type={$styleType}>{$linkText}</test>";
$element = Utility::getElement($html, '//test')[0];
return new Metadata($element);
}
public function setUp(): void
{
CustomOptionTest::$customeRender = new CustomOptionMock(EmbedObjectMock::embeddedModel(''));
CustomOptionTest::$embeddedEntry = EmbedObjectMock::embeddedEntryModel();
CustomOptionTest::$embeddedContentType = EmbedObjectMock::embeddedContentTypeUidModel();
CustomOptionTest::$embeddedAsset = EmbedObjectMock::embeddedAssetModel();
}
public function tearDown(): void{ }
public function testEmbeddedContentTypeEntry(): void
{
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedContentType, $this->getMetadata(EmbedItemType::ENTRY, StyleType::BLOCK));
$this->assertEquals('<div type="entry" sys-style-type="block" ><p>uid</p><p>Content type: <span>contentTypeUid</span></p></div>', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedContentType, $this->getMetadata(EmbedItemType::ENTRY, StyleType::INLINE));
$this->assertEquals('<span type="entry" sys-style-type="inline" >uid</span>', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedContentType, $this->getMetadata(EmbedItemType::ENTRY, StyleType::LINK));
$this->assertEquals('<a type="entry" sys-style-type="link" ></a>', $resultString);
}
public function testEmbeddedEntry(): void
{
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedEntry, $this->getMetadata(EmbedItemType::ENTRY, StyleType::BLOCK));
$this->assertEquals('<div type="entry" sys-style-type="block" ><p>title</p><p>Content type: <span>contentTypeUid</span></p></div>', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedEntry, $this->getMetadata(EmbedItemType::ENTRY, StyleType::INLINE));
$this->assertEquals('<span type="entry" sys-style-type="inline" >title</span>', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedEntry, $this->getMetadata(EmbedItemType::ENTRY, StyleType::LINK));
$this->assertEquals('<a type="entry" sys-style-type="link" ></a>', $resultString);
}
public function testEmbeddedAsset(): void
{
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedAsset, $this->getMetadata(EmbedItemType::ASSET, StyleType::DISPLAY));
$this->assertEquals('<img type="asset" sys-style-type="display" />', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedAsset, $this->getMetadata(EmbedItemType::ASSET, StyleType::DOWNLOAD));
$this->assertEquals('<a type="asset" sys-style-type="download" ></a>', $resultString);
}
public function testEmbeddedContentTypeEntryWithText(): void
{
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedContentType, $this->getMetadata(EmbedItemType::ENTRY, StyleType::BLOCK, CustomOptionTest::$text));
$this->assertEquals('<div type="entry" sys-style-type="block" ><p>uid</p><p>Content type: <span>contentTypeUid</span></p></div>', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedContentType, $this->getMetadata(EmbedItemType::ENTRY, StyleType::INLINE, CustomOptionTest::$text));
$this->assertEquals('<span type="entry" sys-style-type="inline" >uid</span>', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedContentType, $this->getMetadata(EmbedItemType::ENTRY, StyleType::LINK, CustomOptionTest::$text));
$this->assertEquals('<a type="entry" sys-style-type="link" >Text To set Link</a>', $resultString);
}
public function testEmbeddedEntryWithText(): void
{
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedEntry, $this->getMetadata(EmbedItemType::ENTRY, StyleType::BLOCK, CustomOptionTest::$text));
$this->assertEquals('<div type="entry" sys-style-type="block" ><p>title</p><p>Content type: <span>contentTypeUid</span></p></div>', $resultString);
$resultString =
4058
CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedEntry, $this->getMetadata(EmbedItemType::ENTRY, StyleType::INLINE, CustomOptionTest::$text));
$this->assertEquals('<span type="entry" sys-style-type="inline" >title</span>', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedEntry, $this->getMetadata(EmbedItemType::ENTRY, StyleType::LINK, CustomOptionTest::$text));
$this->assertEquals('<a type="entry" sys-style-type="link" >Text To set Link</a>', $resultString);
}
public function testEmbeddedAssetWithText(): void
{
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedAsset, $this->getMetadata(EmbedItemType::ASSET, StyleType::DISPLAY, CustomOptionTest::$text));
$this->assertEquals('<img type="asset" sys-style-type="display" />', $resultString);
$resultString = CustomOptionTest::$customeRender->renderOptions(CustomOptionTest::$embeddedAsset, $this->getMetadata(EmbedItemType::ASSET, StyleType::DOWNLOAD, CustomOptionTest::$text));
$this->assertEquals('<a type="asset" sys-style-type="download" >Text To set Link</a>', $resultString);
}
}