-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Labels
FrameworkBundleRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)
Description
Description
In a functional test, it is useful to check that a specific text is present on an HTML element. For example, at the end of a controller action test, an assertion could be made to check that an entity property has been modified.
The current assertSelectorTextContains
and assertSelectorTextSame
only check the first occurence of a given selector. It is a problem when the element is in an unknown position.
I would like to know if others already had the same issue, and if this 2 functions would be useful for the community (assertAnySelectorTextContains
and assertAnySelectorTextSame
).
Example
A simple example with ul li
selector
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
</ul>
// If the node is at first position
public function testIndexAction(): void
{
$client = self::createClient();
$client->request('GET', '/');
self::assertResponseIsSuccessful();
self::assertSelectorTextContains('ul li', 'test1');
}
// If the node position is known
public function testIndexAction2(): void
{
$client = self::createClient();
$client->request('GET', '/');
self::assertResponseIsSuccessful();
self::assertSelectorTextContains('ul li:nth-child(2)', 'test2');
}
// If the node position is unknown
public function testIndexAction3(): void
{
$client = self::createClient();
$crawler = $client->request('GET', '/');
$this->assertResponseIsSuccessful();
$nodes = $crawler->filter('ul li')->each(fn(Crawler $node) => $node->text());
self::assertResponseIsSuccessful();
self::assertContains('test3', $nodes);
}
Metadata
Metadata
Assignees
Labels
FrameworkBundleRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)