# QueryContentContains Assertion fails with "An unexpected failure occured"

**URL:** https://discourse.laminas.dev/t/querycontentcontains-assertion-fails-with-an-unexpected-failure-occured/2397
**Category:** Components & MVC
**Tags:** laminas-test
**Created:** [July 7, 2021, 9:08am UTC](https://discourse.laminas.dev/t/querycontentcontains-assertion-fails-with-an-unexpected-failure-occured/2397 "2021-07-07T09:08:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![makxk](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/makxk/32/1266_2.png) [@makxk](https://discourse.laminas.dev/u/makxk)
#### Post date: [July 7, 2021, 9:08am UTC](https://discourse.laminas.dev/t/querycontentcontains-assertion-fails-with-an-unexpected-failure-occured/2397/1 "2021-07-07T09:08:33Z")

</div>

Hello everyone!

I’ve been trying to write a test case for an application, which displays a login prompt on its indexAction.  
The goal of this test case is to succeed when the account is not found. I am testing for an error message that’s there when I do it manually.  
Here’s the code:

```auto
public function testIndexActionDisplaysErrorsWhenCredentialsInvalid(){
        $postData = [
            'username' => 'foo',
            'password' => 'bar'
        ];

        $this->dispatch('/', 'POST', $postData);
        $this->assertResponseStatusCode(200);
        $this->assertModuleName('application');
        $this->assertControllerName(IndexController::class); // as specified in router's controller name alias
        $this->assertControllerClass('IndexController');
        $this->assertMatchedRouteName('home');
        $this->assertQueryContentContains('.container #application .text-danger', 'An unexpected failure occured');
    }

```

This test case fails with

```auto
1) ApplicationTest\Controller\IndexControllerTest::testIndexActionDisplaysErrorsWhenCredentialsInvalid
Failed asserting node denoted by .container #application .text-danger CONTAINS content "Account not found", Contents: [An unexpected failure occurred]

C:\Users\js\Documents\Projekte\Management\vendor\laminas\laminas-test\src\PHPUnit\Controller\AbstractHttpControllerTestCase.php:776
C:\Users\js\Documents\Projekte\Management\vendor\laminas\laminas-test\src\PHPUnit\Controller\AbstractHttpControllerTestCase.php:793
C:\Users\js\Documents\Projekte\Management\module\Application\test\Controller\IndexControllerTest.php:51

FAILURES!

```

The twist is: Even when I assert that the content of the node is “An unexpected failure occured”, it still fails:

```auto
There was 1 failure:

1) ApplicationTest\Controller\IndexControllerTest::testIndexActionDisplaysErrorsWhenCredentialsInvalid
Failed asserting node denoted by .container #application .text-danger CONTAINS content "An unexpected failure occured", Contents: [An unexpected failure occurred]

C:\Users\js\Documents\Projekte\Management\vendor\laminas\laminas-test\src\PHPUnit\Controller\AbstractHttpControllerTestCase.php:776
C:\Users\js\Documents\Projekte\Management\vendor\laminas\laminas-test\src\PHPUnit\Controller\AbstractHttpControllerTestCase.php:793
C:\Users\js\Documents\Projekte\Management\module\Application\test\Controller\IndexControllerTest.php:51

FAILURES!
Tests: 1, Assertions: 7, Failures: 1.

```

The page itself is looking like this:

 ![grafik](https://canada1.discourse-cdn.com/flex032/uploads/zendframework/original/2X/d/d47c16f6e174d6cb8a56fd8e8f8fbd4bcd626a13.png)

I already checked the selector for the element, so I am pretty certain that this is not the culprit.  
Any help would be greatly appreciated!

---

<div class="post-metadata">

### Author: ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)
#### Post date: [July 7, 2021, 9:25am UTC](https://discourse.laminas.dev/t/querycontentcontains-assertion-fails-with-an-unexpected-failure-occured/2397/2 "2021-07-07T09:25:49Z")

</div>

> [@makxk](#):
>
> Any help would be greatly appreciated!

Check the content itself with `$this->getResponse()->getContent()` if the expected element is present.

---

<div class="post-metadata">

### Author: ![makxk](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/makxk/32/1266_2.png) [@makxk](https://discourse.laminas.dev/u/makxk)
#### Post date: [July 7, 2021, 9:31am UTC](https://discourse.laminas.dev/t/querycontentcontains-assertion-fails-with-an-unexpected-failure-occured/2397/3 "2021-07-07T09:31:37Z")

</div>

I see. I am getting this HTML back (shortened it before and after the section):

```auto
<form method="POST" name="application" id="application"><div class="text-danger error">An unexpected failure occurred</div>

```

_occurred with double r_. ☹

There’s a hiccup in the authentication process I guess.

Thanks @froschdesign.
