Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Reset default validator translator between tests
Browse files Browse the repository at this point in the history
I noticed when running unit tests that we had an additional error, but
ONLY when the changes introduced for #188 were in place. I tracked it
down to the new test, `testRendersErrorMessagesWithoutDoubleTranslation()`
setting a new default translator.

This patch also makes a few minor changes for code consistency and
readability.
  • Loading branch information
weierophinney committed May 14, 2018
1 parent 25f5b9b commit f49af08
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions test/View/Helper/FormElementErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@

class FormElementErrorsTest extends CommonTestCase
{
/**
* @var null|\Zend\Validator\Translator\TranslatorInterface
*/
protected $defaultTranslator;

public function setUp()
{
$this->defaultTranslator = AbstractValidator::getDefaultTranslator();
$this->helper = new FormElementErrorsHelper();
parent::setUp();
}

public function tearDown()
{
AbstractValidator::setDefaultTranslator($this->defaultTranslator);
}

public function getMessageList()
{
return [
Expand Down Expand Up @@ -81,12 +92,10 @@ public function testRendersErrorMessagesUsingUnorderedListTranslated()
public function testRendersErrorMessagesWithoutDoubleTranslation()
{
$form = new Form('test_form');
$form->add(
[
'name' => 'test_element',
'type' => Element\Color::class,
]
);
$form->add([
'name' => 'test_element',
'type' => Element\Color::class,
]);
$form->setData(['test_element' => 'This is invalid!']);

$mockValidatorTranslator = $this->createMock('Zend\Validator\Translator\TranslatorInterface');
Expand Down Expand Up @@ -121,9 +130,10 @@ function ($message) {

$markup = $this->helper->render($form->get('test_element'));

// @codingStandardsIgnoreStart
$this->assertRegexp('#<ul>\s*<li>TRANSLATED: The input does not match against pattern \'/^#[0-9a-fA-F]{6}$/\'</li>\s*</ul>#s', $markup);
// @codingStandardsIgnoreEnd
$this->assertRegexp(
'#<ul>\s*<li>TRANSLATED: The input does not match against pattern \'/^#[0-9a-fA-F]{6}$/\'</li>\s*</ul>#s',
$markup
);
}

public function testCanSpecifyAttributesForOpeningTag()
Expand Down

0 comments on commit f49af08

Please sign in to comment.