|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use dokuwiki\plugin\prosemirror\schema\Node; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Node tests for the prosemirror plugin |
|
7
|
|
|
* |
|
8
|
|
|
* @group plugin_prosemirror |
|
9
|
|
|
* @group plugins |
|
10
|
|
|
*/ |
|
11
|
|
|
class node_plugin_prosemirror_test extends DokuWikiTest |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
public function test_normnode() |
|
16
|
|
|
{ |
|
17
|
|
|
// empty node |
|
18
|
|
|
$node = new Node('foo'); |
|
19
|
|
|
$this->assertSame('foo', $node->getType()); |
|
20
|
|
|
$this->assertSame(null, $node->getText()); |
|
21
|
|
|
$this->assertJsonStringEqualsJsonString( |
|
22
|
|
|
'{ |
|
23
|
|
|
"type": "foo" |
|
24
|
|
|
}', |
|
25
|
|
|
json_encode($node) |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
// add attributes |
|
29
|
|
|
$node->attr('foo', 'bar'); |
|
30
|
|
|
$node->attr('bar', 'bar'); |
|
31
|
|
|
$node->attr('foo', 'foo'); |
|
32
|
|
|
$this->assertSame('foo', $node->attr('foo')); |
|
33
|
|
|
$this->assertSame('bar', $node->attr('bar')); |
|
34
|
|
|
$this->assertJsonStringEqualsJsonString( |
|
35
|
|
|
'{ |
|
36
|
|
|
"type": "foo", |
|
37
|
|
|
"attrs": { |
|
38
|
|
|
"foo": "foo", |
|
39
|
|
|
"bar": "bar" |
|
40
|
|
|
} |
|
41
|
|
|
}', |
|
42
|
|
|
json_encode($node) |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
// add child |
|
46
|
|
|
$child = new Node('bar'); |
|
47
|
|
|
$node->addChild($child); |
|
48
|
|
|
$this->assertJsonStringEqualsJsonString( |
|
49
|
|
|
'{ |
|
50
|
|
|
"type": "foo", |
|
51
|
|
|
"attrs": { |
|
52
|
|
|
"foo": "foo", |
|
53
|
|
|
"bar": "bar" |
|
54
|
|
|
}, |
|
55
|
|
|
"content": [ |
|
56
|
|
|
{ |
|
57
|
|
|
"type": "bar" |
|
58
|
|
|
} |
|
59
|
|
|
] |
|
60
|
|
|
}', |
|
61
|
|
|
json_encode($node) |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
// set text |
|
65
|
|
|
$this->expectException('\\RuntimeException'); |
|
66
|
|
|
$node->setText('hallo'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function test_textnode() |
|
70
|
|
|
{ |
|
71
|
|
|
// empty node |
|
72
|
|
|
$node = new Node('text'); |
|
73
|
|
|
$this->assertSame('text', $node->getType()); |
|
74
|
|
|
$this->assertSame('', $node->getText()); |
|
75
|
|
|
$this->assertJsonStringEqualsJsonString( |
|
76
|
|
|
'{ |
|
77
|
|
|
"type": "text", |
|
78
|
|
|
"text": "" |
|
79
|
|
|
}', |
|
80
|
|
|
json_encode($node) |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
// add attributes |
|
84
|
|
|
$node->attr('foo', 'bar'); |
|
85
|
|
|
$node->attr('bar', 'bar'); |
|
86
|
|
|
$node->attr('foo', 'foo'); |
|
87
|
|
|
$this->assertSame('foo', $node->attr('foo')); |
|
88
|
|
|
$this->assertSame('bar', $node->attr('bar')); |
|
89
|
|
|
$this->assertJsonStringEqualsJsonString( |
|
90
|
|
|
'{ |
|
91
|
|
|
"type": "text", |
|
92
|
|
|
"text": "", |
|
93
|
|
|
"attrs": { |
|
94
|
|
|
"foo": "foo", |
|
95
|
|
|
"bar": "bar" |
|
96
|
|
|
} |
|
97
|
|
|
}', |
|
98
|
|
|
json_encode($node) |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
// add text |
|
102
|
|
|
$node->setText('hallo'); |
|
103
|
|
|
$this->assertJsonStringEqualsJsonString( |
|
104
|
|
|
'{ |
|
105
|
|
|
"type": "text", |
|
106
|
|
|
"attrs": { |
|
107
|
|
|
"foo": "foo", |
|
108
|
|
|
"bar": "bar" |
|
109
|
|
|
}, |
|
110
|
|
|
"text": "hallo" |
|
111
|
|
|
}', |
|
112
|
|
|
json_encode($node) |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
|
|
// add child |
|
116
|
|
|
$this->expectException('\\RuntimeException'); |
|
117
|
|
|
$child = new Node('bar'); |
|
118
|
|
|
$node->addChild($child); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|