Skip to content

Commit 0213f58

Browse files
Fix MentionParserTest
1 parent 5acb3ce commit 0213f58

File tree

1 file changed

+7
-114
lines changed

1 file changed

+7
-114
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,193 +1,86 @@
11
<?php
22

3-
4-
5-
63
use App\Open\MentionParser;
74

85
test('it replaces mention elements with their corresponding values', function () {
9-
106
$content = '<p>Hello <span mention mention-field-id="123">Placeholder</span></p>';
11-
12-
$data = [['nf_id' => '123', 'value' => 'World']];
13-
14-
15-
7+
$data = [['id' => '123', 'value' => 'World']];
168

179
$parser = new MentionParser($content, $data);
18-
1910
$result = $parser->parse();
2011

21-
22-
23-
2412
expect($result)->toBe('<p>Hello World</p>');
25-
2613
});
2714

28-
29-
30-
3115
test('it handles multiple mentions', function () {
32-
3316
$content = '<p><span mention mention-field-id="123">Name</span> is <span mention mention-field-id="456">Age</span> years old</p>';
34-
3517
$data = [
36-
37-
['nf_id' => '123', 'value' => 'John'],
38-
39-
['nf_id' => '456', 'value' => 30],
40-
18+
['id' => '123', 'value' => 'John'],
19+
['id' => '456', 'value' => 30],
4120
];
4221

43-
44-
45-
4622
$parser = new MentionParser($content, $data);
47-
4823
$result = $parser->parse();
4924

50-
51-
52-
5325
expect($result)->toBe('<p>John is 30 years old</p>');
54-
5526
});
5627

57-
58-
59-
6028
test('it uses fallback when value is not found', function () {
61-
6229
$content = '<p>Hello <span mention mention-field-id="123" mention-fallback="Friend">Placeholder</span></p>';
63-
6430
$data = [];
6531

66-
67-
68-
6932
$parser = new MentionParser($content, $data);
70-
7133
$result = $parser->parse();
7234

73-
74-
75-
7635
expect($result)->toBe('<p>Hello Friend</p>');
77-
7836
});
7937

80-
81-
82-
8338
test('it removes mention element when no value and no fallback', function () {
84-
8539
$content = '<p>Hello <span mention mention-field-id="123">Placeholder</span></p>';
86-
8740
$data = [];
8841

89-
90-
91-
9242
$parser = new MentionParser($content, $data);
93-
9443
$result = $parser->parse();
9544

96-
97-
98-
9945
expect($result)->toBe('<p>Hello </p>');
100-
10146
});
10247

103-
104-
105-
10648
test('it handles array values', function () {
107-
10849
$content = '<p>Tags: <span mention mention-field-id="123">Placeholder</span></p>';
109-
110-
$data = [['nf_id' => '123', 'value' => ['PHP', 'Laravel', 'Testing']]];
111-
112-
113-
50+
$data = [['id' => '123', 'value' => ['PHP', 'Laravel', 'Testing']]];
11451

11552
$parser = new MentionParser($content, $data);
116-
11753
$result = $parser->parse();
11854

119-
120-
121-
12255
expect($result)->toBe('<p>Tags: PHP, Laravel, Testing</p>');
123-
12456
});
12557

126-
127-
128-
12958
test('it preserves HTML structure', function () {
130-
13159
$content = '<div><p>Hello <span mention mention-field-id="123">Placeholder</span></p><p>How are you?</p></div>';
132-
133-
$data = [['nf_id' => '123', 'value' => 'World']];
134-
135-
136-
60+
$data = [['id' => '123', 'value' => 'World']];
13761

13862
$parser = new MentionParser($content, $data);
139-
14063
$result = $parser->parse();
14164

142-
143-
144-
14565
expect($result)->toBe('<div><p>Hello World</p><p>How are you?</p></div>');
146-
14766
});
14867

149-
150-
151-
15268
test('it handles UTF-8 characters', function () {
153-
15469
$content = '<p>こんにちは <span mention mention-field-id="123">Placeholder</span></p>';
155-
156-
$data = [['nf_id' => '123', 'value' => '世界']];
157-
158-
159-
70+
$data = [['id' => '123', 'value' => '世界']];
16071

16172
$parser = new MentionParser($content, $data);
162-
16373
$result = $parser->parse();
16474

165-
166-
167-
16875
expect($result)->toBe('<p>こんにちは 世界</p>');
169-
17076
});
17177

172-
173-
174-
17578
test('it handles content without surrounding paragraph tags', function () {
176-
17779
$content = 'some text <span contenteditable="false" mention="" mention-field-id="123" mention-field-name="Post excerpt" mention-fallback="">Post excerpt</span> dewde';
178-
179-
$data = [['nf_id' => '123', 'value' => 'replaced text']];
180-
181-
182-
80+
$data = [['id' => '123', 'value' => 'replaced text']];
18381

18482
$parser = new MentionParser($content, $data);
185-
18683
$result = $parser->parse();
18784

188-
189-
190-
19185
expect($result)->toBe('some text replaced text dewde');
192-
19386
});

0 commit comments

Comments
 (0)