TailwindTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 238
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 113
dl 0
loc 238
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testSolid() 0 22 1
A testBanner() 0 20 1
A testLeftAccentBorder() 0 17 1
A testTopAccentBorder() 0 29 1
A testTitled() 0 28 1
A testTraditional() 0 17 1
A testModernWithBadge() 0 27 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Widgets\Tests\Alert;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Definitions\Exception\CircularReferenceException;
9
use Yiisoft\Definitions\Exception\InvalidConfigException;
10
use Yiisoft\Definitions\Exception\NotInstantiableException;
11
use Yiisoft\Factory\NotFoundException;
12
use Yiisoft\Yii\Widgets\Alert;
13
use Yiisoft\Yii\Widgets\Tests\Support\Assert;
14
use Yiisoft\Yii\Widgets\Tests\Support\TestTrait;
15
16
/**
17
 * @psalm-suppress PropertyNotSetInConstructor
18
 */
19
final class TailwindTest extends TestCase
20
{
21
    use TestTrait;
22
23
    /**
24
     * @link https://v1.tailwindcss.com/components/alerts#banner
25
     *
26
     * @throws CircularReferenceException
27
     * @throws InvalidConfigException
28
     * @throws NotFoundException
29
     * @throws NotInstantiableException
30
     */
31
    public function testBanner(): void
32
    {
33
        Assert::equalsWithoutLE(
34
            <<<HTML
35
            <div id="w0-alert" class="bg-blue-100 border-b border-blue-500 border-t px-4 py-3 text-blue-700" role="alert">
36
            <span class="align-middle inline-block mr-8"><p class="font-bold">Informational message</p><p class="text-sm">Some additional text to explain said message.</p></span>
37
            <button type="button" class="float-right px-4 py-3" onclick="closeAlert()">&times;</button>
38
            </div>
39
            HTML,
40
            Alert::widget()
41
                ->body(
0 ignored issues
show
Bug introduced by
The method body() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Yii\Widgets\Alert. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
                ->/** @scrutinizer ignore-call */ body(
Loading history...
42
                    '<p class="font-bold">Informational message</p>' .
43
                    '<p class="text-sm">Some additional text to explain said message.</p>'
44
                )
45
                ->bodyClass('align-middle inline-block mr-8')
46
                ->buttonClass('float-right px-4 py-3')
47
                ->buttonOnClick('closeAlert()')
48
                ->class('bg-blue-100 border-b border-blue-500 border-t px-4 py-3 text-blue-700')
49
                ->id('w0-alert')
50
                ->render(),
51
        );
52
    }
53
54
    /**
55
     * @link https://v1.tailwindcss.com/components/alerts#left-accent-border
56
     *
57
     * @throws CircularReferenceException
58
     * @throws InvalidConfigException
59
     * @throws NotFoundException
60
     * @throws NotInstantiableException
61
     */
62
    public function testLeftAccentBorder(): void
63
    {
64
        Assert::equalsWithoutLE(
65
            <<<HTML
66
            <div id="w0-alert" class="bg-yellow-100 border-l-2 border-yellow-500 p-4 text-yellow-700" role="alert">
67
            <span class="align-middle inline-block mr-8"><p><b>Be Warned</b></p> <p>Something not ideal might be happening.</p></span>
68
            <button type="button" class="absolute bottom-0 px-4 py-3 right-0 top-0" onclick="closeAlert()">&times;</button>
69
            </div>
70
            HTML,
71
            Alert::widget()
72
                ->body('<p><b>Be Warned</b></p> <p>Something not ideal might be happening.</p>')
73
                ->bodyClass('align-middle inline-block mr-8')
74
                ->buttonClass('absolute bottom-0 px-4 py-3 right-0 top-0')
75
                ->buttonOnClick('closeAlert()')
76
                ->class('bg-yellow-100 border-l-2 border-yellow-500 p-4 text-yellow-700')
77
                ->id('w0-alert')
78
                ->render(),
79
        );
80
    }
81
82
    /**
83
     * @link https://v1.tailwindcss.com/components/alerts#modern-with-badge
84
     *
85
     * @throws CircularReferenceException
86
     * @throws InvalidConfigException
87
     * @throws NotFoundException
88
     * @throws NotInstantiableException
89
     */
90
    public function testModernWithBadge(): void
91
    {
92
        Assert::equalsWithoutLE(
93
            <<<HTML
94
            <div id="w0-alert" class="bg-gray-900 lg:px-4 py-4 text-center text-white" role="alert">
95
            <button type="button" class="bottom-0 px-4 py-3 right-0 top-0" onclick="closeAlert()">&times;</button>
96
            <div class="bg-gray-800 p-2 flex items-center leading-none lg:inline-flex lg:rounded-full">
97
            <div class="bg-gray-500 flex font-bold ml-2 mr-3 px-2 py-1 rounded-full text-xs uppercase"><i class="not-italic">🔔 New </i></div>
98
            <span class="flex-auto font-semibold mr-2 text-left">Get the coolest t-shirts from our brand new store</span>
99
            </div>
100
            </div>
101
            HTML,
102
            Alert::widget()
103
                ->body('Get the coolest t-shirts from our brand new store')
104
                ->bodyClass('flex-auto font-semibold mr-2 text-left')
105
                ->bodyContainer(true)
106
                ->bodyContainerClass('bg-gray-800 p-2 flex items-center leading-none lg:inline-flex lg:rounded-full')
107
                ->buttonClass('bottom-0 px-4 py-3 right-0 top-0')
108
                ->buttonOnClick('closeAlert()')
109
                ->class('bg-gray-900 lg:px-4 py-4 text-center text-white')
110
                ->iconClass('not-italic')
111
                ->iconContainerClass('bg-gray-500 flex font-bold ml-2 mr-3 px-2 py-1 rounded-full text-xs uppercase')
112
                ->iconText('🔔 New ')
113
                ->id('w0-alert')
114
                ->layoutBody('{icon}{body}')
115
                ->layoutHeader('{button}')
116
                ->render(),
117
        );
118
    }
119
120
    /**
121
     * @link https://v1.tailwindcss.com/components/alerts#solid
122
     *
123
     * @throws CircularReferenceException
124
     * @throws InvalidConfigException
125
     * @throws NotFoundException
126
     * @throws NotInstantiableException
127
     */
128
    public function testSolid(): void
129
    {
130
        Assert::equalsWithoutLE(
131
            <<<HTML
132
            <div id="w0-alert" class="bg-blue-500 flex font-bold items-center px-4 py-3 text-sm text-white" role="alert">
133
            <div><i class="pr-2">i</i></div>
134
            <p class="align-middle flex-grow inline-block mr-8">Something happened that you should know about.</p>
135
            <button type="button" class="float-right px-4 py-3" onclick="closeAlert()">&times;</button>
136
            </div>
137
            HTML,
138
            Alert::widget()
139
                ->body('Something happened that you should know about.')
140
                ->bodyClass('align-middle flex-grow inline-block mr-8')
141
                ->bodyTag('p')
142
                ->buttonClass('float-right px-4 py-3')
143
                ->buttonOnClick('closeAlert()')
144
                ->class('bg-blue-500 flex font-bold items-center px-4 py-3 text-sm text-white')
145
                ->iconClass('pr-2')
146
                ->iconText('i')
147
                ->id('w0-alert')
148
                ->layoutBody('{icon}{body}{button}')
149
                ->render(),
150
        );
151
    }
152
153
    /**
154
     * @link https://v1.tailwindcss.com/components/alerts#traditional
155
     *
156
     * @throws CircularReferenceException
157
     * @throws InvalidConfigException
158
     * @throws NotFoundException
159
     * @throws NotInstantiableException
160
     */
161
    public function testTraditional(): void
162
    {
163
        Assert::equalsWithoutLE(
164
            <<<HTML
165
            <div id="w0-alert" class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
166
            <span class="align-middle inline-block mr-8"><b>Holy smokes!</b> Something seriously bad happened.</span>
167
            <button type="button" class="absolute bottom-0 px-4 py-3 right-0 top-0" onclick="closeAlert()">&times;</button>
168
            </div>
169
            HTML,
170
            Alert::widget()
171
                ->body('<b>Holy smokes!</b> Something seriously bad happened.')
172
                ->bodyClass('align-middle inline-block mr-8')
173
                ->buttonClass('absolute bottom-0 px-4 py-3 right-0 top-0')
174
                ->buttonOnClick('closeAlert()')
175
                ->class('bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative')
176
                ->id('w0-alert')
177
                ->render(),
178
        );
179
    }
180
181
    /**
182
     * @link https://v1.tailwindcss.com/components/alerts#titled
183
     *
184
     * @throws CircularReferenceException
185
     * @throws InvalidConfigException
186
     * @throws NotFoundException
187
     * @throws NotInstantiableException
188
     */
189
    public function testTitled(): void
190
    {
191
        Assert::equalsWithoutLE(
192
            <<<HTML
193
            <div id="w0-alert" role="alert">
194
            <div class="bg-red-500 font-bold px-4 py-2 rounded-t text-white">
195
            <span class="font-semibold">Danger</span>
196
            </div>
197
            <div class="bg-red-100 border border-red-400 border-t-0 rounded-b text-red-700">
198
            <span class="align-middle inline-block mr-8 px-4 py-3">Something not ideal might be happening.</span>
199
            <button type="button" class="float-right px-4 py-3" onclick="closeAlert()">&times;</button>
200
            </div>
201
            </div>
202
            HTML,
203
            Alert::widget()
204
                ->body('Something not ideal might be happening.')
205
                ->bodyClass('align-middle inline-block mr-8 px-4 py-3')
206
                ->bodyContainer(true)
207
                ->bodyContainerClass('bg-red-100 border border-red-400 border-t-0 rounded-b text-red-700')
208
                ->buttonClass('float-right px-4 py-3')
209
                ->buttonOnClick('closeAlert()')
210
                ->header('Danger')
211
                ->headerClass('font-semibold')
212
                ->headerContainer()
213
                ->headerContainerClass('bg-red-500 font-bold px-4 py-2 rounded-t text-white')
214
                ->id('w0-alert')
215
                ->layoutHeader('{header}')
216
                ->render(),
217
        );
218
    }
219
220
    /**
221
     * @link https://v1.tailwindcss.com/components/alerts#top-accent-border
222
     *
223
     * @throws CircularReferenceException
224
     * @throws InvalidConfigException
225
     * @throws NotFoundException
226
     * @throws NotInstantiableException
227
     */
228
    public function testTopAccentBorder(): void
229
    {
230
        Assert::equalsWithoutLE(
231
            <<<HTML
232
            <div id="w0-alert" class="bg-green-100 border-t-4 border-green-500 px-4 py-3 rounded-b shadow-md text-green-900" role="alert">
233
            <div class="flex">
234
            <div class="fill-current h-6 mr-4 py-1 text-green-500 w-6"><i class="not-italic">🛈</i></div>
235
            <span class="align-middle inline-block flex-grow mr-8"><p class="font-bold">Our privacy policy has changed</p><p class="text-sm">Make sure you know how these changes affect you.</p></span>
236
            <button type="button" class="float-right px-4 py-3" onclick="closeAlert()">&times;</button>
237
            </div>
238
            </div>
239
            HTML,
240
            Alert::widget()
241
                ->attributes(['id' => 'w0-alert'])
0 ignored issues
show
Bug introduced by
The method attributes() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Yii\Widgets\Alert or Yiisoft\Yii\Widgets\Menu or Yiisoft\Yii\Widgets\Breadcrumbs. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

241
                ->/** @scrutinizer ignore-call */ attributes(['id' => 'w0-alert'])
Loading history...
242
                ->body(
243
                    '<p class="font-bold">Our privacy policy has changed</p>' .
244
                    '<p class="text-sm">Make sure you know how these changes affect you.</p>'
245
                )
246
                ->bodyClass('align-middle inline-block flex-grow mr-8')
247
                ->bodyContainer(true)
248
                ->bodyContainerClass('flex')
249
                ->buttonClass('float-right px-4 py-3')
250
                ->buttonOnClick('closeAlert()')
251
                ->class('bg-green-100 border-t-4 border-green-500 px-4 py-3 rounded-b shadow-md text-green-900')
252
                ->iconClass('not-italic')
253
                ->iconContainerClass('fill-current h-6 mr-4 py-1 text-green-500 w-6')
254
                ->iconText('🛈')
255
                ->layoutBody('{icon}{body}{button}')
256
                ->render(),
257
        );
258
    }
259
}
260