From: Jeremy Benoist Date: Fri, 11 Mar 2016 08:42:08 +0000 (+0100) Subject: Improve test failure readability X-Git-Tag: 2.0.0~17^2~9 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=4f9cf232f8d4d750d39aca83406b8a6d5e17a6c9;p=github%2Fwallabag%2Fwallabag.git Improve test failure readability If the response content isn't the one expected, instead of checking into the whole DOM (with node tag, etc ..) we only check the text. So if it fails, phpunit will display only the text, not all node tag. It'll be easier to read. --- diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 1930a2ae..d24066b3 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -210,7 +210,7 @@ class ConfigController extends Controller public function deleteTaggingRuleAction(TaggingRule $rule) { if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { - throw $this->createAccessDeniedException('You can not access this tagging ryle.'); + throw $this->createAccessDeniedException('You can not access this tagging rule.'); } $em = $this->getDoctrine()->getManager(); diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index bf455f32..884e740e 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -418,11 +418,6 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - if (500 == $client->getResponse()->getStatusCode()) { - var_export($client->getResponse()->getContent()); - die(); - } - $this->assertEquals(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=rss_config_save]')->form(); @@ -556,12 +551,14 @@ class ConfigControllerTest extends WallabagCoreTestCase $form = $crawler->filter('button[id=tagging_rule_save]')->form(); - $client->submit($form, $data); + $crawler = $client->submit($form, $data); $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); + foreach ($messages as $message) { - $this->assertContains($message, $client->getResponse()->getContent()); + $this->assertContains($message, $body[0]); } } @@ -574,9 +571,11 @@ class ConfigControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:TaggingRule') ->findAll()[0]; - $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); + $crawler = $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); + $this->assertEquals(403, $client->getResponse()->getStatusCode()); - $this->assertContains('You can not access this tagging ryle', $client->getResponse()->getContent()); + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); + $this->assertContains('You can not access this tagging rule', $body[0]); } public function testDemoMode() diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 0fcf323c..46fbaf91 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -25,10 +25,11 @@ class EntryControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/unread/list'); - $client->followRedirect(); + $crawler = $client->followRedirect(); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertContains('quickstart.intro.paragraph_1', $client->getResponse()->getContent()); + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); + $this->assertContains('quickstart.intro.paragraph_1', $body[0]); // Test if quickstart is disabled when user has 1 entry $crawler = $client->request('GET', '/new'); @@ -45,8 +46,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); $client->followRedirect(); - $client->request('GET', '/unread/list'); - $this->assertContains('entry.list.number_on_the_page', $client->getResponse()->getContent()); + $crawler = $client->request('GET', '/unread/list'); + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); + $this->assertContains('entry.list.number_on_the_page', $body[0]); } public function testGetNew() @@ -240,10 +242,11 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); - $client->request('GET', '/view/'.$content->getId()); + $crawler = $client->request('GET', '/view/'.$content->getId()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); + $this->assertContains($content->getTitle(), $body[0]); } /**