-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Arr::isEmpty() but make sure is_empty still works
- Loading branch information
1 parent
4b6fd3d
commit c8c8189
Showing
4 changed files
with
48 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Tests\Modifiers; | ||
|
||
use Statamic\Facades\Antlers; | ||
use Statamic\Support\Str; | ||
use Tests\TestCase; | ||
|
||
class IsEmptyTest extends TestCase | ||
{ | ||
/** @test */ | ||
function it_checks_if_its_empty() | ||
{ | ||
$this->assertTrue($this->parse('')); // empty string is empty | ||
$this->assertTrue($this->parse([])); // empty array is empty | ||
|
||
$this->assertFalse($this->parse(['foo' => 'bar'])); // definitely not empty | ||
|
||
$this->assertTrue($this->parse(['foo' => ''])); // just consists of empty strings | ||
$this->assertTrue($this->parse(['foo' => '', 'bar' => ''])); | ||
|
||
$this->assertFalse($this->parse(null)); // nulls are not empty | ||
$this->assertFalse($this->parse(['foo' => null])); // array of nulls are not empty | ||
$this->assertFalse($this->parse(['foo' => '', 'bar' => null])); | ||
|
||
$this->assertTrue($this->parse(['foo' => []])); // recursion | ||
$this->assertTrue($this->parse(['foo' => ['bar' => []]])); | ||
$this->assertTrue($this->parse(['foo' => ['bar' => ['baz' => '']]])); | ||
$this->assertFalse($this->parse(['foo' => ['bar' => ['baz' => 'qux']]])); | ||
$this->assertFalse($this->parse(['foo' => ['bar' => ['baz' => null]]])); | ||
} | ||
|
||
function parse($arr) | ||
{ | ||
return Str::toBool(Antlers::parse('{{ if arr|is_empty }}true{{ else }}false{{ /if }}', ['arr' => $arr])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters