File tree 4 files changed +86
-1
lines changed
4 files changed +86
-1
lines changed Original file line number Diff line number Diff line change @@ -95,14 +95,40 @@ public function last(string $selector): ViewAssertion
95
95
public function contains (string $ text ): ViewAssertion
96
96
{
97
97
Assert::assertStringContainsString (
98
- (string ) $ text ,
98
+ (string )$ text ,
99
99
$ this ->html ,
100
100
"Failed asserting that the text ` {$ text }` exists within ` {$ this ->html }`. "
101
101
);
102
102
103
103
return $ this ;
104
104
}
105
105
106
+ /**
107
+ * Asserts that the view, at given selector, is empty.
108
+ */
109
+ public function empty (): ViewAssertion
110
+ {
111
+ Assert::assertEmpty (
112
+ $ this ->crawler ->html (),
113
+ "Failed asserting that the text ` {$ this ->crawler ->html ()}` is empty. "
114
+ );
115
+
116
+ return $ this ;
117
+ }
118
+
119
+ /**
120
+ * Asserts that the view, at given selector, is not empty.
121
+ */
122
+ public function notEmpty (): ViewAssertion
123
+ {
124
+ Assert::assertNotEmpty (
125
+ $ this ->crawler ->html (),
126
+ "Failed asserting that the text ` {$ this ->crawler ->html ()}` is not empty. "
127
+ );
128
+
129
+ return $ this ;
130
+ }
131
+
106
132
/**
107
133
* Asserts that the view, at the **root element**, contains the given attribute value.
108
134
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+
4
+ namespace Tests ;
5
+
6
+ use NunoMaduro \LaravelMojito \InteractsWithViews ;
7
+ use PHPUnit \Framework \AssertionFailedError ;
8
+ use PHPUnit \Framework \TestCase ;
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ final class AssertEmpty extends TestCase
14
+ {
15
+ use InteractsWithViews;
16
+
17
+ public function testEmpty (): void
18
+ {
19
+ $ this ->assertView ('empty ' )->in ('.empty-div ' )->empty ();
20
+ }
21
+
22
+ public function testNotEmpty (): void
23
+ {
24
+ $ this ->expectException (AssertionFailedError::class);
25
+
26
+ $ this ->assertView ('button ' )->in ('.btn ' )->empty ();
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+
4
+ namespace Tests ;
5
+
6
+ use NunoMaduro \LaravelMojito \InteractsWithViews ;
7
+ use PHPUnit \Framework \AssertionFailedError ;
8
+ use PHPUnit \Framework \TestCase ;
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ final class AssertNotEmpty extends TestCase
14
+ {
15
+ use InteractsWithViews;
16
+
17
+ public function testEmpty (): void
18
+ {
19
+ $ this ->assertView ('button ' )->in ('.btn ' )->notEmpty ();
20
+ }
21
+
22
+ public function testNotEmpty (): void
23
+ {
24
+ $ this ->expectException (AssertionFailedError::class);
25
+
26
+ $ this ->assertView ('empty ' )->in ('.empty-div ' )->notEmpty ();
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ < div >
2
+ < div class ="empty-div "> </ div >
3
+ </ div >
You can’t perform that action at this time.
0 commit comments