|
4 | 4 |
|
5 | 5 | namespace Devscast\EditorJs\Tests\Blocks; |
6 | 6 |
|
7 | | -use Devscast\EditorJs\BlockFactory; |
8 | | -use Devscast\EditorJs\Blocks\Attaches; |
9 | | -use Devscast\EditorJs\Exception\EditorException; |
10 | | -use PHPUnit\Framework\TestCase; |
11 | | - |
12 | | -class AttachesTest extends TestCase |
| 7 | +class AttachesTest extends AbstractBlockTest |
13 | 8 | { |
14 | | - private const array VALID_DATA = [ |
15 | | - 'file' => [ |
16 | | - 'url' => 'https://example.com/file.pdf', |
17 | | - 'size' => 1024, |
18 | | - 'name' => 'document.pdf', |
19 | | - 'extension' => 'pdf', |
20 | | - ], |
21 | | - 'title' => 'Important Document', |
22 | | - ]; |
23 | | - |
24 | | - public function testValidConstruction(): void |
25 | | - { |
26 | | - $attaches = new Attaches( |
27 | | - id: 'test123', |
28 | | - type: 'attaches', |
29 | | - data: self::VALID_DATA |
30 | | - ); |
31 | | - |
32 | | - $this->assertInstanceOf(Attaches::class, $attaches); |
33 | | - } |
34 | | - |
35 | | - public function testInvalidTypeConstruction(): void |
36 | | - { |
37 | | - $this->expectException(EditorException::class); |
38 | | - |
39 | | - new Attaches( |
40 | | - id: 'test123', |
41 | | - type: 'invalid-type', |
42 | | - data: self::VALID_DATA |
43 | | - ); |
44 | | - } |
45 | | - |
46 | | - public function testMissingFileDataConstruction(): void |
47 | | - { |
48 | | - $this->expectException(EditorException::class); |
49 | | - |
50 | | - $invalidData = self::VALID_DATA; |
51 | | - unset($invalidData['file']); |
52 | | - |
53 | | - new Attaches( |
54 | | - id: 'test123', |
55 | | - type: 'attaches', |
56 | | - data: $invalidData |
57 | | - ); |
58 | | - } |
59 | | - |
60 | | - public function testMissingFilePropertiesConstruction(): void |
61 | | - { |
62 | | - $testCases = [ |
63 | | - 'missing url' => 'url', |
64 | | - 'missing size' => 'size', |
65 | | - 'missing name' => 'name', |
66 | | - 'missing extension' => 'extension', |
67 | | - ]; |
68 | | - |
69 | | - foreach ($testCases as $case => $property) { |
70 | | - $this->expectException(EditorException::class); |
71 | | - // dd($case, $property); |
72 | | - $invalidData = self::VALID_DATA; |
73 | | - unset($invalidData['file'][$property]); |
74 | | - new Attaches( |
75 | | - id: 'test123', |
76 | | - type: 'attaches', |
77 | | - data: $invalidData |
78 | | - ); |
79 | | - } |
80 | | - } |
81 | | - |
82 | | - public function testMissingTitleConstruction(): void |
83 | | - { |
84 | | - $this->expectException(EditorException::class); |
85 | | - $invalidData = self::VALID_DATA; |
86 | | - unset($invalidData['title']); |
87 | | - new Attaches( |
88 | | - id: 'test123', |
89 | | - type: 'attaches', |
90 | | - data: $invalidData |
91 | | - ); |
92 | | - } |
93 | | - |
94 | | - public function testToHtml(): void |
| 9 | + #[\Override] |
| 10 | + public static function getValidSchemasProvider(): \Generator |
95 | 11 | { |
96 | | - $attaches = new Attaches( |
97 | | - id: 'test123', |
98 | | - type: 'attaches', |
99 | | - data: self::VALID_DATA |
100 | | - ); |
101 | | - $html = $attaches->toHtml(); |
102 | | - $this->assertStringContainsString('<div id="test123">', $html); |
103 | | - $this->assertStringContainsString( |
104 | | - 'href="https://example.com/file.pdf"', |
105 | | - $html |
106 | | - ); |
107 | | - $this->assertStringContainsString( |
108 | | - 'title="Important Document"', |
109 | | - $html |
110 | | - ); |
111 | | - $this->assertStringContainsString( |
112 | | - '<strong>document.pdf</strong> (1024 bytes)', |
113 | | - $html |
114 | | - ); |
| 12 | + yield []; |
115 | 13 | } |
116 | 14 |
|
117 | | - public function testFactoryCreation(): void |
| 15 | + #[\Override] |
| 16 | + public static function getInvalidSchemasProvider(): \Generator |
118 | 17 | { |
119 | | - $data = <<<JSON |
120 | | - { |
121 | | - "time": 1739980616433, |
122 | | - "blocks": [ |
123 | | - { |
124 | | - "id": "XKNT99-qqS", |
125 | | - "type": "attaches", |
126 | | - "data": { |
127 | | - "file": { |
128 | | - "url": "https://drive.google.com/user/catalog/my-file.pdf", |
129 | | - "size": 12902, |
130 | | - "name": "file.pdf", |
131 | | - "extension": "pdf" |
132 | | - }, |
133 | | - "title": "My file" |
134 | | - } |
135 | | - } |
136 | | - ] |
137 | | - } |
138 | | - JSON; |
139 | | - |
140 | | - $blocks = BlockFactory::parse($data, ['attaches']); |
141 | | - $this->assertCount(1, $blocks); |
142 | | - $this->assertInstanceOf(Attaches::class, $blocks[0]); |
143 | | - } |
144 | | - |
145 | | - public function testFactoryCreationWithInvalidData(): void |
146 | | - { |
147 | | - $this->expectException(EditorException::class); |
148 | | - |
149 | | - $data = <<<JSON |
150 | | - { |
151 | | - "time": 1739980616433, |
152 | | - "blocks": [ |
153 | | - { |
154 | | - "id": "XKNT99-qqS", |
155 | | - "type": "attaches", |
156 | | - "data": { |
157 | | - "file": { |
158 | | - "url": "https://drive.google.com/user/catalog/my-file.pdf", |
159 | | - "size": 12902 |
160 | | - }, |
161 | | - "title": "My file" |
162 | | - } |
163 | | - } |
164 | | - ] |
165 | | - } |
166 | | - JSON; |
167 | | - |
168 | | - BlockFactory::parse($data, ['attaches']); |
| 18 | + yield []; |
169 | 19 | } |
170 | 20 | } |
0 commit comments