-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathButtonTest.php
More file actions
128 lines (106 loc) · 3.91 KB
/
ButtonTest.php
File metadata and controls
128 lines (106 loc) · 3.91 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
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace Sebastienheyd\Boilerplate\Tests\Datatables;
use Sebastienheyd\Boilerplate\Datatables\Button;
use Sebastienheyd\Boilerplate\Tests\TestCase;
class ButtonTest extends TestCase
{
public function testTooltipMethod()
{
$button = Button::add('Test Button')
->link('/test')
->tooltip('This is a tooltip')
->make();
$this->assertStringContainsString('title="This is a tooltip"', $button);
}
public function testTooltipNotAddedWhenEmpty()
{
$button = Button::add('Test Button')
->link('/test')
->make();
$this->assertStringNotContainsString('title=', $button);
}
public function testTooltipMethodChaining()
{
$button = Button::add('Test')
->link('/test')
->tooltip('Tooltip text')
->color('primary')
->icon('star')
->make();
$this->assertStringContainsString('title="Tooltip text"', $button);
$this->assertStringContainsString('btn-primary', $button);
$this->assertStringContainsString('fa-star', $button);
}
public function testButtonHtmlStructure()
{
$button = Button::add('Click me')
->link('/action')
->tooltip('Button tooltip')
->color('success')
->make();
$this->assertMatchesRegularExpression('/<a href="\/action" title="Button tooltip" class="btn btn-sm btn-success/', $button);
}
public function testCustomButtonWithRoute()
{
// Define a test route
$this->app['router']->get('/test/{id}', function () {
return 'test';
})->name('test.route');
$button = Button::custom(
'test.route',
['id' => 1],
'star',
'Custom tooltip',
'success'
);
$this->assertStringContainsString('title="Custom tooltip"', $button);
$this->assertStringContainsString('btn-success', $button);
$this->assertStringContainsString('fa-star', $button);
$this->assertStringContainsString('/test/1', $button);
}
public function testCustomButtonWithAttributes()
{
$this->app['router']->get('/test', function () {
return 'test';
})->name('test.route2');
$button = Button::custom(
'test.route2',
[],
'heart',
'Custom tooltip',
'primary',
['data-action' => 'custom-action', 'data-id' => '123']
);
$this->assertStringContainsString('data-action="custom-action"', $button);
$this->assertStringContainsString('data-id="123"', $button);
$this->assertStringContainsString('btn-primary', $button);
$this->assertStringContainsString('fa-heart', $button);
}
public function testCustomButtonWithDefaults()
{
$this->app['router']->get('/default', function () {
return 'test';
})->name('test.default');
$button = Button::custom('test.default');
$this->assertStringNotContainsString('title=', $button);
$this->assertStringContainsString('btn-default', $button);
$this->assertStringNotContainsString('fa-', $button); // No icon by default
}
public function testCustomButtonArgumentOrder()
{
// Test that $icon comes before $tooltip in the method signature
$this->app['router']->get('/order', function () {
return 'test';
})->name('test.order');
$button = Button::custom(
'test.order',
[],
'cog', // $icon (3rd parameter)
'Tooltip', // $tooltip (4th parameter)
'warning' // $color (5th parameter)
);
$this->assertStringContainsString('fa-cog', $button);
$this->assertStringContainsString('title="Tooltip"', $button);
$this->assertStringContainsString('btn-warning', $button);
}
}