Issue
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.
Solution
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))
Answered By - SystemGlitch
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.