-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathMarkTest.php
More file actions
106 lines (82 loc) · 2.95 KB
/
MarkTest.php
File metadata and controls
106 lines (82 loc) · 2.95 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
namespace Tests\Modifiers;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Fields\Field;
use Statamic\Fields\Value;
use Statamic\Fieldtypes\Bard;
use Statamic\Fieldtypes\Markdown;
use Statamic\Modifiers\Modify;
use Tests\TestCase;
class MarkTest extends TestCase
{
#[Test]
public function it_marks()
{
$value = 'Lorem, ipsum dolor sit amet';
$words = 'lorem sit';
$expected = '<mark>Lorem</mark>, ipsum dolor <mark>sit</mark> amet';
$this->assertEquals($expected, $this->modify($value, $words));
}
#[Test]
public function it_marks_with_class()
{
$value = 'Lorem, ipsum dolor sit amet';
$words = 'ipsum';
$param = 'class:highlight';
$expected = 'Lorem, <mark class="highlight">ipsum</mark> dolor sit amet';
$this->assertEquals($expected, $this->modify($value, $words, $param));
}
#[Test]
public function it_marks_with_tags()
{
$value = 'Lorem, ipsum <x-amet class="ipsum">dolor</x-amet> sit amet';
$words = 'ipsum amet';
$expected = 'Lorem, <mark>ipsum</mark> <x-amet class="ipsum">dolor</x-amet> sit <mark>amet</mark>';
$this->assertEquals($expected, $this->modify($value, $words));
}
#[Test]
public function it_marks_with_specialchars()
{
$value = 'Lorem, ipsum < 4 dolor > 2 sit amet';
$words = 'dolor';
$expected = 'Lorem, ipsum < 4 <mark>dolor</mark> > 2 sit amet';
$this->assertEquals($expected, $this->modify($value, $words));
}
#[Test]
public function it_marks_with_entities()
{
$value = 'Lorem, ipsum elüt sit amet';
$words = 'elüt';
$expected = 'Lorem, ipsum <mark>elüt</mark> sit amet';
$this->assertEquals($expected, $this->modify($value, $words));
}
#[Test]
public function it_marks_bard_value()
{
$data = new Value([
[
'type' => 'paragraph',
'content' => [
['type' => 'text', 'text' => 'Lorem, ipsum elüt sit '],
['type' => 'text', 'text' => 'amet', 'marks' => [['type' => 'bold']]],
],
],
], 'content', (new Bard)->setField(new Field('test', [])));
$words = 'elüt amet';
$expected = '<p>Lorem, ipsum <mark>elüt</mark> sit <strong><mark>amet</mark></strong></p>';
$this->assertEquals($expected, $this->modify($data->value(), $words));
}
#[Test]
public function it_marks_markdown_value()
{
$data = new Value('Lorem, ipsum elüt sit **amet**', 'content', new Markdown());
$words = 'elüt amet';
$expected = '<p>Lorem, ipsum <mark>elüt</mark> sit <strong><mark>amet</mark></strong></p>
';
$this->assertEquals($expected, $this->modify($data->value(), $words));
}
protected function modify($arr, ...$args)
{
return Modify::value($arr)->mark($args)->fetch();
}
}