-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathGeneralTest.php
More file actions
116 lines (90 loc) · 3.84 KB
/
Copy pathGeneralTest.php
File metadata and controls
116 lines (90 loc) · 3.84 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
<?php
use EditorJS\ConfigLoader;
use EditorJS\EditorJS;
use EditorJS\EditorJSException;
/**
* Class GeneralTest
*
* Check basic config and block data parsing functionality
*/
class GeneralTest extends TestCase
{
const SAMPLE_VALID_DATA = '{"time":1537444483710,"blocks":[{"type":"header","data":{"text":"CodeX Editor","level":2}},{"type":"paragraph","data":{"text":"Привет. Перед вами наш обновленный редактор. На этой странице вы можете проверить его в действии — попробуйте отредактировать или дополнить материал. Код страницы содержит пример подключения и простейшей настройки."}}],"version":"2.0.3"}';
const EMPTY_DATA = '';
const CONFIGURATION_FILE = TESTS_DIR . "/samples/test-config.json";
private $config = '';
public function setUp()
{
$this->config = file_get_contents(GeneralTest::CONFIGURATION_FILE);
}
public function testValidData()
{
new EditorJS(GeneralTest::SAMPLE_VALID_DATA, $this->config);
}
public function testNullInput()
{
$callable = function () {
new EditorJS('', $this->config);
};
$this->assertException($callable, EditorJSException::class, null, 'JSON is empty');
}
public function testEmptyArray()
{
$callable = function () {
new EditorJS('{}', $this->config);
};
$this->assertException($callable, EditorJSException::class, null, 'Input array is empty');
}
public function testWrongJson()
{
$callable = function () {
new EditorJS('{[{', $this->config);
};
$this->assertException($callable, EditorJSException::class, null, 'Wrong JSON format: Syntax error');
}
public function testValidConfig()
{
new ConfigLoader(file_get_contents(TESTS_DIR . "/samples/test-config.json"));
}
public function testItemsMissed()
{
$callable = function () {
new EditorJS('{"s":""}', $this->config);
};
$this->assertException($callable, EditorJSException::class, null, 'Field `blocks` is missing');
}
public function testUnicode()
{
$callable = function () {
new EditorJS('{"s":"😀"}', $this->config);
};
$this->assertException($callable, EditorJSException::class, null, 'Field `blocks` is missing');
}
public function testInvalidBlock()
{
$callable = function () {
new EditorJS('{"blocks":""}', $this->config);
};
$this->assertException($callable, EditorJSException::class, null, 'Blocks is not an array');
}
public function testBlocksContent()
{
$callable = function () {
new EditorJS('{"blocks":["",""]}', $this->config);
};
$this->assertException($callable, EditorJSException::class, null, 'Block must be an Array');
}
public function testNested()
{
$data = '{"blocks":[{"type":"table","data":{"header": {"description":"a table", "author": "codex"}, "rows": [["name", "age", "sex"],["Paul", "24", "male"],["Ann", "26", "female"]]}}]}';
$editor = new EditorJS($data, $this->config);
$result = $editor->getBlocks();
$valid_rows = [["name", "age", "sex"],["Paul", "24", "male"],["Ann", "26", "female"]];
$this->assertEquals('a table', $result[0]['data']['header']['description']);
$this->assertEquals('codex', $result[0]['data']['header']['author']);
$this->assertEquals(3, count($result[0]['data']['rows']));
$this->assertEquals('name', $result[0]['data']['rows'][0][0]);
$this->assertEquals('24', $result[0]['data']['rows'][1][1]);
$this->assertEquals('female', $result[0]['data']['rows'][2][2]);
}
}