I'm using PHP Faker to generate random data (using factories) in the database and sometimes it generates apostrophes.
In my test, I use assertSeeText()
.
The problem is that when the tested string contains special characters such as apostrophes, these characters are converted to html entities in the view so the assertion is false.
$siteShow = factory(Site::class)->create();
$this->get('admin/site/'. $siteShow->id_site)
->assertStatus(200)
->assertSeeText($siteShow->name)
->assertSeeText($siteShow->address)
Example case when the assertions fail: $siteShow->name
equals O'Neil
. It fails because in the view it appears as O'Neil
.
My question is: how do I make it so that the assertion is true in both cases: the name in the view is O'Neil
or O'Neil
? I would like the solution to handle any html entity if possible. Thank you in advance.
I found a solution. As my views are generated by Blade using the {{ ... }}
syntax, the text is escaped and passed through htmlspecialchars()
and if I'm correct, more especially through the e()
helper. So I just did the following and it works:
$siteShow = factory(Site::class)->create();
$this->get('admin/site/'. $siteShow->id_site)
->assertStatus(200)
->assertSeeText(e($siteShow->name))
->assertSeeText(e($siteShow->address))
SystemGlitch's answer didn't work for me and I think the best way is to use the second boolean parameter for assertSeeText
and assertSee
to disable escaping
$siteShow = factory(Site::class)->create();
$this->get('admin/site/'. $siteShow->id_site)
->assertSeeText($siteShow->name,false)
->assertSeeText($siteShow->address,false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With