forked from ARCANEDEV/php-html
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
196 additions
and
38 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
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,30 @@ | ||
<?php namespace Arcanedev\Html\Tests\Elements; | ||
|
||
use Arcanedev\Html\Elements\Element; | ||
|
||
/** | ||
* Class HtmlElementTest | ||
* | ||
* @package Arcanedev\Html\Tests\Elements | ||
* @author ARCANEDEV <arcanedev.maroc@gmail.com> | ||
*/ | ||
class HtmlElementTest extends TestCase | ||
{ | ||
/* ----------------------------------------------------------------- | ||
| Tests | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
/** @test */ | ||
public function it_can_register_a_macro() | ||
{ | ||
Element::macro('btnPrimary', function () { | ||
return $this->class('btn btn-primary'); | ||
}); | ||
|
||
$elt = Element::withTag('a'); | ||
|
||
static::assertEquals('<a></a>', $elt->toHtml()); | ||
static::assertEquals('<a class="btn btn-primary"></a>', $elt->btnPrimary()->toHtml()); | ||
} | ||
} |
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,104 @@ | ||
<?php namespace Arcanedev\Html\Tests\Entities; | ||
|
||
use Arcanedev\Html\Elements\Span; | ||
use Arcanedev\Html\Entities\ChildrenCollection; | ||
use Arcanedev\Html\Tests\TestCase; | ||
|
||
/** | ||
* Class ChildrenCollectionTest | ||
* | ||
* @package Arcanedev\Html\Tests\Entities | ||
* @author ARCANEDEV <arcanedev.maroc@gmail.com> | ||
*/ | ||
class ChildrenCollectionTest extends TestCase | ||
{ | ||
/* ----------------------------------------------------------------- | ||
| Tests | ||
| ----------------------------------------------------------------- | ||
*/ | ||
|
||
/** @test */ | ||
public function it_can_be_instantiated() | ||
{ | ||
$children = new ChildrenCollection; | ||
|
||
$expectations = [ | ||
\Arcanedev\Html\Contracts\Renderable::class, | ||
\Illuminate\Support\Collection::class, | ||
]; | ||
|
||
foreach ($expectations as $expected) { | ||
static::assertInstanceOf($expected, $children); | ||
} | ||
|
||
static::assertCount(0, $children); | ||
static::assertTrue($children->isEmpty()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_parse_children() | ||
{ | ||
$children = ChildrenCollection::parse(['foo', null, 'bar']); | ||
|
||
static::assertCount(3, $children); | ||
static::assertEquals(['foo', null, 'bar'], $children->all()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_convert_to_html() | ||
{ | ||
$children = ChildrenCollection::parse(['foo', null, 'bar'], function ($child) { | ||
return ! is_null($child) | ||
? Span::make()->html($child) | ||
: $child; | ||
}); | ||
|
||
static::assertCount(3, $children); | ||
static::assertEquals('<span>foo</span><span>bar</span>', $children->toHtml()); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @dataProvider getInvalidChildrenToParseDataProvider | ||
* | ||
* @param mixed $child | ||
* | ||
* @expectedException \Arcanedev\Html\Exceptions\InvalidChildException | ||
*/ | ||
public function it_must_throw_exception_on_parse_with_invalid_child($child) | ||
{ | ||
ChildrenCollection::parse($child); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @dataProvider getInvalidChildrenToParseDataProvider | ||
* | ||
* @param mixed $child | ||
* | ||
* @expectedException \Arcanedev\Html\Exceptions\InvalidChildException | ||
*/ | ||
public function it_must_throw_exception_on_convert_to_html_with_invalid_child($child) | ||
{ | ||
ChildrenCollection::make([$child])->toHtml(); | ||
} | ||
|
||
/** | ||
* >DATA PROVIDER | ||
* | ||
* @see it_must_throw_exception_on_parse_with_invalid_child | ||
* @see it_must_throw_exception_on_convert_to_html_with_invalid_child | ||
* | ||
* @return array | ||
*/ | ||
public function getInvalidChildrenToParseDataProvider() | ||
{ | ||
return [ | ||
[true], | ||
[1], | ||
[.1], | ||
]; | ||
} | ||
} |
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