Skip to content

Commit

Permalink
Merge pull request #10 from bavix/develop
Browse files Browse the repository at this point in the history
add "placeholder" attribute
  • Loading branch information
rez1dent3 committed Jan 27, 2020
2 parents 99cb58c + de1c40c commit b30d27c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
5 changes: 3 additions & 2 deletions helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
$attributes = [
'href', 'src', 'id', 'class', 'name',
'text', 'height', 'width', 'content',
'value', 'title', 'alt'
'value', 'title', 'alt',
'placeholder',
];

$tags = [
Expand All @@ -24,7 +25,7 @@
'param', 'pre', 'script', 'section', 'select', 'small', 'source', 'span',
'strong', 'style', 'sub', 'sup', 'table', 'tbody', 'td',
'textarea', 'tfoot', 'th', 'thead', 'title', 'tr',
'track', 'u', 'ul', 'var', 'video'
'track', 'u', 'ul', 'var', 'video',
];

$tags = \implode('|', $tags);
Expand Down
60 changes: 39 additions & 21 deletions tests/AdvancedHtmlDom/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
class BaseTest extends Unit
{

public function testHelpers()
/**
* @return void
*/
public function testHelpers(): void
{
$file = fileGetHtml(
$this->partial('base.simple')
);
$file = fileGetHtml($this->partial('base.simple'));

$str = strGetHtml(
\file_get_contents(
Expand All @@ -27,11 +28,12 @@ public function testHelpers()
);
}

public function testSimple()
/**
* @return void
*/
public function testSimple(): void
{
$this->dom->loadFile(
$this->partial('base.simple')
);
$this->dom->loadFile($this->partial('base.simple'));

preg_match('~<h1.*>(.+)</h1>~', $this->dom->html(), $outs);

Expand All @@ -51,11 +53,12 @@ public function testSimple()
);
}

public function testId()
/**
* @return void
*/
public function testId(): void
{
$this->dom->loadFile(
$this->partial('base.simple')
);
$this->dom->loadFile($this->partial('base.simple'));

$this->assertSame(
$this->dom->find('#id')->tag,
Expand All @@ -73,21 +76,36 @@ public function testId()
);
}

public function testUl()
/**
* @return void
*/
public function testUl(): void
{
$this->dom->loadFile(
$this->partial('base.simple')
);
$this->dom->loadFile($this->partial('base.simple'));

$ul = $this->dom->find('ul');

// var_dump($ul->());die;
$items = [];
foreach ($ul as $ulItem) {
foreach ($ulItem->childNodes as $childNode) {
$items[] = (int)$childNode->innerText;
}
}

// foreach ($li as $item)
// {
//
// }
$this->assertCount(3, $items);
$this->assertEquals(6, array_sum($items));
}

/**
* @return void
*/
public function testPlaceholder(): void
{
$this->dom->loadFile($this->partial('base.simple'));
$input = $this->dom->find('input[placeholder]');
foreach ($input as $item) {
$this->assertEquals($item->value, $item->placeholder);
}
}

}
8 changes: 2 additions & 6 deletions tests/AdvancedHtmlDom/ModifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ class ModifyTest extends Unit
/**
* @expectedException \InvalidArgumentException
*/
public function testSimple()
public function testSimple(): void
{
$this->dom->loadFile(
$this->partial('base.simple')
);

$this->dom->loadFile($this->partial('base.simple'));
$h1 = $this->dom->find('h1');

$h1->class = __CLASS__;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/data/base/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ <h1 class="text-center h w">Hello World</h1>
<li>3</li>
</ul>

<form>
<input type="password" value="my pass" placeholder="my pass">
</form>

</body>
</html>

0 comments on commit b30d27c

Please sign in to comment.