Skip to content

Commit

Permalink
Add Decoy::hasEl()
Browse files Browse the repository at this point in the history
Returns a boolean for whether an Element key exists in the elements yaml file(s).  Closes #64
  • Loading branch information
weotch committed Aug 29, 2017
1 parent a4ee25f commit 926d2f8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions classes/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ public function el($key)
return app('decoy.elements')->localize($this->locale())->get($key);
}

/**
* Check if the Element key exists
*
* @param string $key
* @return boolean
*/
public function hasEl($key)
{
return app('decoy.elements')
->localize($this->locale())
->hydrate()
->has($key);
}

/**
* Is Decoy handling the request? Check if the current path is exactly "admin" or if
* it contains admin/*
Expand Down
5 changes: 4 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
stopOnFailure="false">

<testsuites>
<testsuite name="Integrtion Tests">
<testsuite name="Integration Tests">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
<testsuite name="Unit Tests">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>

<filter>
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/ElementsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace Tests\Unit;

use Bkwld\Decoy\Helpers;
use Tests\TestCase;

class ElementsTest extends TestCase
{

/**
* Test `Decoy::hasEl()`
*
* @return [type] [description]
*/
public function testHasEl()
{
$this->assertTrue((new Helpers)->hasEl('homepage.marquee.title'));
$this->assertFalse((new Helpers)->hasEl('homepage.fake.title'));
}

}

0 comments on commit 926d2f8

Please sign in to comment.