From d5ac7aa0b2e78b00195cf0cb76dcfeabc7da4839 Mon Sep 17 00:00:00 2001 From: Val Bancer Date: Sun, 11 Nov 2018 17:00:55 +0100 Subject: [PATCH] Simplify assertions in tests --- .../Console/Command/Task/ExtractTaskTest.php | 69 +++++-------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php index 5c5b0b3d4..050985ea2 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php @@ -380,25 +380,12 @@ class ExtractTaskTest extends CakeTestCase { $this->Task->execute(); $result = file_get_contents($this->path . DS . 'default.pot'); - - $pattern = preg_quote('#Model/PersisterOne.php:validation for field title#', '/'); - $this->assertRegExp($pattern, $result); - - $pattern = preg_quote('#Model/PersisterOne.php:validation for field body#', '/'); - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post title is required"#'; - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "You may enter up to %s chars \(minimum is %s chars\)"#'; - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post body is required"#'; - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post body is super required"#'; - $this->assertRegExp($pattern, $result); - + $this->assertContains('Model/PersisterOne.php:validation for field title', $result); + $this->assertContains('Model/PersisterOne.php:validation for field body', $result); + $this->assertContains('msgid "Post title is required"', $result); + $this->assertContains('msgid "You may enter up to %s chars (minimum is %s chars)"', $result); + $this->assertContains('msgid "Post body is required"', $result); + $this->assertContains('msgid "Post body is super required"', $result); $this->assertContains('msgid "double \\"quoted\\" validation"', $result, 'Strings with quotes not handled correctly'); $this->assertContains("msgid \"single 'quoted' validation\"", $result, 'Strings with quotes not handled correctly'); } @@ -429,21 +416,11 @@ class ExtractTaskTest extends CakeTestCase { $this->Task->execute(); $result = file_get_contents($this->path . DS . 'test_plugin.pot'); - - $pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#', '/'); - $this->assertRegExp($pattern, $result); - - $pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field body#', '/'); - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post title is required"#'; - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post body is required"#'; - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post body is super required"#'; - $this->assertRegExp($pattern, $result); + $this->assertContains('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title', $result); + $this->assertContains('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field body', $result); + $this->assertContains('msgid "Post title is required"', $result); + $this->assertContains('msgid "Post body is required"', $result); + $this->assertContains('msgid "Post body is super required"', $result); } /** @@ -468,24 +445,12 @@ class ExtractTaskTest extends CakeTestCase { $this->Task->execute(); $result = file_get_contents($this->path . DS . 'test_plugin.pot'); - - $pattern = preg_quote('#Model/TestPluginPost.php:validation for field title#', '/'); - $this->assertRegExp($pattern, $result); - - $pattern = preg_quote('#Model/TestPluginPost.php:validation for field body#', '/'); - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post title is required"#'; - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post body is required"#'; - $this->assertRegExp($pattern, $result); - - $pattern = '#msgid "Post body is super required"#'; - $this->assertRegExp($pattern, $result); - - $pattern = '#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#'; - $this->assertNotRegExp($pattern, $result); + $this->assertContains('Model/TestPluginPost.php:validation for field title', $result); + $this->assertContains('Model/TestPluginPost.php:validation for field body', $result); + $this->assertContains('msgid "Post title is required"', $result); + $this->assertContains('msgid "Post body is required"', $result); + $this->assertContains('msgid "Post body is super required"', $result); + $this->assertNotContains('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title', $result); } /**