Skip to content

Commit

Permalink
[+]: add one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Mar 23, 2020
1 parent 301e41c commit 5b1854e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/HtmlDomParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1976,4 +1976,41 @@ public function testIssue42()
$d->loadHtml('<div><p>p1</p></div>');
static::assertSame('<div><p>p1</p></div>', (string) $d);
}

public function testFindClassTest()
{
$html = "
<div class='services'></div> or
<div class='services last-item'></div> or
<div class='services active'></div>
";

$d = new voku\helper\HtmlDomParser();
$d->load($html);

$htmlResult = '';
foreach ($d->find('.services') as $e) {
$e->setAttribute('data-foo', 'bar');
$htmlResult .= $e->html();
};

$htmlExpected = '<div class="services" data-foo="bar"></div><div class="services last-item" data-foo="bar"></div><div class="services active" data-foo="bar"></div>';

static::assertSame($htmlExpected, $htmlResult);

// ---

$d = new voku\helper\HtmlDomParser();
$d->load($html);

$htmlResult = '';
foreach ($d->find('div[class~=services]') as $e) {
$e->setAttribute('data-foo', 'bar');
$htmlResult .= $e->html();
};

$htmlExpected = '<div class="services" data-foo="bar"></div><div class="services last-item" data-foo="bar"></div><div class="services active" data-foo="bar"></div>';

static::assertSame($htmlExpected, $htmlResult);
}
}

0 comments on commit 5b1854e

Please sign in to comment.