Simplify assertions in tests

This commit is contained in:
Val Bancer 2018-11-11 17:00:55 +01:00
parent 90ddb43632
commit d5ac7aa0b2

View file

@ -380,25 +380,12 @@ class ExtractTaskTest extends CakeTestCase {
$this->Task->execute(); $this->Task->execute();
$result = file_get_contents($this->path . DS . 'default.pot'); $result = file_get_contents($this->path . DS . 'default.pot');
$this->assertContains('Model/PersisterOne.php:validation for field title', $result);
$pattern = preg_quote('#Model/PersisterOne.php:validation for field title#', '/'); $this->assertContains('Model/PersisterOne.php:validation for field body', $result);
$this->assertRegExp($pattern, $result); $this->assertContains('msgid "Post title is required"', $result);
$this->assertContains('msgid "You may enter up to %s chars (minimum is %s chars)"', $result);
$pattern = preg_quote('#Model/PersisterOne.php:validation for field body#', '/'); $this->assertContains('msgid "Post body is required"', $result);
$this->assertRegExp($pattern, $result); $this->assertContains('msgid "Post body is super required"', $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('msgid "double \\"quoted\\" validation"', $result, 'Strings with quotes not handled correctly'); $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'); $this->assertContains("msgid \"single 'quoted' validation\"", $result, 'Strings with quotes not handled correctly');
} }
@ -429,21 +416,11 @@ class ExtractTaskTest extends CakeTestCase {
$this->Task->execute(); $this->Task->execute();
$result = file_get_contents($this->path . DS . 'test_plugin.pot'); $result = file_get_contents($this->path . DS . 'test_plugin.pot');
$this->assertContains('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title', $result);
$pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#', '/'); $this->assertContains('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field body', $result);
$this->assertRegExp($pattern, $result); $this->assertContains('msgid "Post title is required"', $result);
$this->assertContains('msgid "Post body is required"', $result);
$pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field body#', '/'); $this->assertContains('msgid "Post body is super required"', $result);
$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);
} }
/** /**
@ -468,24 +445,12 @@ class ExtractTaskTest extends CakeTestCase {
$this->Task->execute(); $this->Task->execute();
$result = file_get_contents($this->path . DS . 'test_plugin.pot'); $result = file_get_contents($this->path . DS . 'test_plugin.pot');
$this->assertContains('Model/TestPluginPost.php:validation for field title', $result);
$pattern = preg_quote('#Model/TestPluginPost.php:validation for field title#', '/'); $this->assertContains('Model/TestPluginPost.php:validation for field body', $result);
$this->assertRegExp($pattern, $result); $this->assertContains('msgid "Post title is required"', $result);
$this->assertContains('msgid "Post body is required"', $result);
$pattern = preg_quote('#Model/TestPluginPost.php:validation for field body#', '/'); $this->assertContains('msgid "Post body is super required"', $result);
$this->assertRegExp($pattern, $result); $this->assertNotContains('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title', $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);
} }
/** /**