Skip to content

Commit

Permalink
Test replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Aug 23, 2020
1 parent 3a6861b commit b211aec
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
10 changes: 5 additions & 5 deletions src/Decorators/AbstractDataHandlerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public function getLabel(): ?HtmlTag

protected function _prepareForProduce(): HtmlElement
{
$this->addClass('p-form-field');
$this->addClass('p-form__field');
if($this->_handler->getErrors())
{
$this->addClass('p-form-field--error');
$this->addClass('p-form__field--error');
}
return parent::_prepareForProduce();
}
Expand Down Expand Up @@ -168,15 +168,15 @@ protected function _formatElements(HtmlTag $input, ?HtmlTag $label, ?HtmlTag $er
$return = array_fill_keys($this->getElementOrder(), null);
if(array_key_exists(self::LABEL, $return) && $label)
{
$return[self::LABEL] = Div::create($label)->addClass('p-form--label');
$return[self::LABEL] = Div::create($label)->addClass('p-form__label');
}
if(array_key_exists(self::ERRORS, $return) && $errors)
{
$return[self::ERRORS] = Div::create($errors)->addClass('p-form--errors');
$return[self::ERRORS] = Div::create($errors)->addClass('p-form__errors');
}
if(array_key_exists(self::INPUT, $return))
{
$return[self::INPUT] = Div::create($input)->addClass('p-form--input');
$return[self::INPUT] = Div::create($input)->addClass('p-form__input');
}

// array merge, but don't replace existing
Expand Down
2 changes: 1 addition & 1 deletion src/Decorators/CheckboxDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private function _getContainer(Input $checkbox, $label)
return Div::create(
$checkbox,
Label::create($label)->setAttribute('for', $checkbox->getId())
)->addClass('p-form--checkbox');
)->addClass('p-form__checkbox');
}

protected function _formatElements(HtmlTag $input, ?HtmlTag $label, ?HtmlTag $errors)
Expand Down
2 changes: 1 addition & 1 deletion src/Decorators/RadioDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function _configureInputElement(HtmlElement $input)
$radio->setAttribute('checked', true);
}
$options[] = Div::create($radio, Label::create($label)->setAttribute('for', $radio->getid()))
->addClass('p-form--checkbox');
->addClass('p-form__checkbox');
}
$input->setContent($options);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/DataHandlers/AbstractDataHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ public function testRender()
{
$fdh = new ReadOnlyDataHandler();
$this->assertEquals(
'<div class="p-form-field"><div class="p-form--label"><label></label></div><div class="p-form--input"><span></span></div></div>',
'<div class="p-form__field"><div class="p-form__label"><label></label></div><div class="p-form__input"><span></span></div></div>',
$fdh->getDecorator()->render()
);

$fdh = new ReadOnlyDataHandler();
$fdh->setName('myName');
$this->assertRegExp(
'/<div class="p-form-field"><div class="p-form--label"><label for="(my-name-...)">My Name<\/label><\/div><div class="p-form--input"><span id="\1"><\/span><\/div><\/div>/',
'/<div class="p-form__field"><div class="p-form__label"><label for="(my-name-...)">My Name<\/label><\/div><div class="p-form__input"><span id="\1"><\/span><\/div><\/div>/',
$fdh->getDecorator()->render()
);

$fdh = new ReadOnlyDataHandler();
$fdh->setName('myName');
$fdh->setLabel('This is my input');
$this->assertRegExp(
'/<div class="p-form-field"><div class="p-form--label"><label for="(my-name-...)">This is my input<\/label><\/div><div class="p-form--input"><span id="\1"><\/span><\/div><\/div>/',
'/<div class="p-form__field"><div class="p-form__label"><label for="(my-name-...)">This is my input<\/label><\/div><div class="p-form__input"><span id="\1"><\/span><\/div><\/div>/',
$fdh->getDecorator()->render()
);

Expand All @@ -88,7 +88,7 @@ public function testRender()
$fdh->setLabel('This is my input');
$fdh->setValue('my value');
$this->assertRegExp(
'/<div class="p-form-field"><div class="p-form--label"><label for="(my-name-...)">This is my input<\/label><\/div><div class="p-form--input"><span id="\1">my value<\/span><\/div><\/div>/',
'/<div class="p-form__field"><div class="p-form__label"><label for="(my-name-...)">This is my input<\/label><\/div><div class="p-form__input"><span id="\1">my value<\/span><\/div><\/div>/',
$fdh->getDecorator()->render()
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/DataHandlers/BooleanHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ public function testCheckbox()
$this->assertTrue($h->isValid());

$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--input"><div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice" value="true" /><label for="\1">Do You Agree\?</label></div></div></div></div>~',
'~<div class="p-form__field"><div class="p-form__input"><div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice" value="true" /><label for="\1">Do You Agree\?</label></div></div></div></div>~',
$decorator->render()
);

$h->setValueFormatted('yes');
$this->assertTrue($h->isValid());
$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--input"><div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice" value="true" checked /><label for="\1">Do You Agree\?</label></div></div></div></div>~',
'~<div class="p-form__field"><div class="p-form__input"><div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice" value="true" checked /><label for="\1">Do You Agree\?</label></div></div></div></div>~',
$decorator->render()
);

$decorator->setRequired(true);
$this->assertTrue($decorator->isRequired());
$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--input"><div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice" value="true" checked required /><label for="\1">Do You Agree\?</label></div></div></div></div>~',
'~<div class="p-form__field"><div class="p-form__input"><div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice" value="true" checked required /><label for="\1">Do You Agree\?</label></div></div></div></div>~',
$decorator->render()
);
}
Expand Down
20 changes: 10 additions & 10 deletions tests/DataHandlers/EnumDataHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public function testGetElement()
{
$ele = new EnumDataHandler();
$this->assertEquals(
'<div class="p-form-field"><div class="p-form--label"><label></label></div><div class="p-form--input"><select></select></div></div>',
'<div class="p-form__field"><div class="p-form__label"><label></label></div><div class="p-form__input"><select></select></div></div>',
$ele->getDecorator()->render()
);

$ele = new EnumDataHandler();
$ele->setOptions(['a' => 'one', 'b' => 'two']);
$ele->validate();
$this->assertEquals(
'<div class="p-form-field p-form-field--error"><div class="p-form--label"><label></label></div><div class="p-form--errors"><ul><li>not a valid value</li></ul></div><div class="p-form--input"><select><option value="a">one</option><option value="b">two</option></select></div></div>',
'<div class="p-form__field p-form__field--error"><div class="p-form__label"><label></label></div><div class="p-form__errors"><ul><li>not a valid value</li></ul></div><div class="p-form__input"><select><option value="a">one</option><option value="b">two</option></select></div></div>',
$ele->getDecorator()->render()
);

Expand All @@ -31,7 +31,7 @@ public function testGetElement()
$ele->setValue('b');
$ele->validate();
$this->assertEquals(
'<div class="p-form-field"><div class="p-form--label"><label></label></div><div class="p-form--input"><select><option value="a">one</option><option value="b" selected>two</option></select></div></div>',
'<div class="p-form__field"><div class="p-form__label"><label></label></div><div class="p-form__input"><select><option value="a">one</option><option value="b" selected>two</option></select></div></div>',
$ele->getDecorator()->render()
);

Expand All @@ -43,7 +43,7 @@ public function testGetElement()
$this->assertTrue($ele->isValidValue('c'));

$this->assertEquals(
'<div class="p-form-field"><div class="p-form--label"><label></label></div><div class="p-form--input"><select><option value="a">one</option><option value="b" selected>two</option><option value="c">three</option></select></div></div>',
'<div class="p-form__field"><div class="p-form__label"><label></label></div><div class="p-form__input"><select><option value="a">one</option><option value="b" selected>two</option><option value="c">three</option></select></div></div>',
$ele->getDecorator()->render()
);

Expand All @@ -52,7 +52,7 @@ public function testGetElement()
/** @var SelectDecorator $dec */
$ele->getDecorator()->getInput()->setId('mySelect');
$this->assertEquals(
'<div class="p-form-field"><div class="p-form--label"><label for="mySelect"></label></div><div class="p-form--input"><select id="mySelect"><option value="a">one</option><option value="b" selected>two</option><option value="c">three</option></select></div></div>',
'<div class="p-form__field"><div class="p-form__label"><label for="mySelect"></label></div><div class="p-form__input"><select id="mySelect"><option value="a">one</option><option value="b" selected>two</option><option value="c">three</option></select></div></div>',
$ele->getDecorator()->render()
);
}
Expand All @@ -65,7 +65,7 @@ public function testCheckboxEnum()
$h->setOptions(['one' => 'First', 'two' => 'Second', 'three' => 'Third']);
$h->validate();
$this->assertRegExp(
'~<div class="p-form-field p-form-field--error"><div class="p-form--label"><label>Select One</label></div><div class="p-form--errors"><ul><li>must be an array</li></ul></div><div class="p-form--input"><div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="one" /><label for="\1">First</label></div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="two" /><label for="\2">Second</label></div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="three" /><label for="\3">Third</label></div></div></div></div>~',
'~<div class="p-form__field p-form__field--error"><div class="p-form__label"><label>Select One</label></div><div class="p-form__errors"><ul><li>must be an array</li></ul></div><div class="p-form__input"><div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="one" /><label for="\1">First</label></div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="two" /><label for="\2">Second</label></div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="three" /><label for="\3">Third</label></div></div></div></div>~',
$h->getDecorator()->render()
);

Expand All @@ -76,7 +76,7 @@ public function testCheckboxEnum()
$h->setValueFormatted('one');
$h->validate();
$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--label"><label>Select One</label></div><div class="p-form--input"><div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="one" checked /><label for="\1">First</label></div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="two" /><label for="\2">Second</label></div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="three" /><label for="\3">Third</label></div></div></div></div>~',
'~<div class="p-form__field"><div class="p-form__label"><label>Select One</label></div><div class="p-form__input"><div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="one" checked /><label for="\1">First</label></div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="two" /><label for="\2">Second</label></div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="three" /><label for="\3">Third</label></div></div></div></div>~',
$h->getDecorator()->render()
);

Expand All @@ -87,7 +87,7 @@ public function testCheckboxEnum()
$h->setValueFormatted(['one', 'three']);
$h->validate();
$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--label"><label>Select One</label></div><div class="p-form--input"><div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="one" checked /><label for="\1">First</label></div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="two" /><label for="\2">Second</label></div><div class="p-form--checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="three" checked /><label for="\3">Third</label></div></div></div></div>~',
'~<div class="p-form__field"><div class="p-form__label"><label>Select One</label></div><div class="p-form__input"><div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="one" checked /><label for="\1">First</label></div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="two" /><label for="\2">Second</label></div><div class="p-form__checkbox"><input type="checkbox" id="(mychoice-...-...)" name="mychoice\[\]" value="three" checked /><label for="\3">Third</label></div></div></div></div>~',
$h->getDecorator()->render()
);
}
Expand All @@ -102,7 +102,7 @@ public function testRadioEnum()
$h->validate();

$this->assertRegExp(
'~<div class="p-form-field p-form-field--error"><div class="p-form--label"><label>Select One</label></div><div class="p-form--errors"><ul><li>not a valid value</li></ul></div><div class="p-form--input"><div><div class="p-form--checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="one" /><label for="\1">First</label></div><div class="p-form--checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="two" /><label for="\2">Second</label></div><div class="p-form--checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="three" /><label for="\3">Third</label></div></div></div></div>~',
'~<div class="p-form__field p-form__field--error"><div class="p-form__label"><label>Select One</label></div><div class="p-form__errors"><ul><li>not a valid value</li></ul></div><div class="p-form__input"><div><div class="p-form__checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="one" /><label for="\1">First</label></div><div class="p-form__checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="two" /><label for="\2">Second</label></div><div class="p-form__checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="three" /><label for="\3">Third</label></div></div></div></div>~',
$h->getDecorator()->render()
);

Expand All @@ -115,7 +115,7 @@ public function testRadioEnum()
$h->validate();

$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--label"><label>Select One</label></div><div class="p-form--input"><div><div class="p-form--checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="one" checked /><label for="\1">First</label></div><div class="p-form--checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="two" /><label for="\2">Second</label></div><div class="p-form--checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="three" /><label for="\3">Third</label></div></div></div></div>~',
'~<div class="p-form__field"><div class="p-form__label"><label>Select One</label></div><div class="p-form__input"><div><div class="p-form__checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="one" checked /><label for="\1">First</label></div><div class="p-form__checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="two" /><label for="\2">Second</label></div><div class="p-form__checkbox"><input type="radio" id="(mychoice-...-...)" name="mychoice" value="three" /><label for="\3">Third</label></div></div></div></div>~',
$h->getDecorator()->render()
);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/DataHandlers/TextDataHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public function testTextHandler()
$text->setName('test');
$text->setValue('my text');
$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--label"><label for="test-(...)">Test</label></div><div class="p-form--input"><input type="text" id="test-\1" name="test" placeholder="Test" value="my text" /></div></div>~',
'~<div class="p-form__field"><div class="p-form__label"><label for="test-(...)">Test</label></div><div class="p-form__input"><input type="text" id="test-\1" name="test" placeholder="Test" value="my text" /></div></div>~',
$text->getDecorator()->render()
);
$text->getDecorator()->getLabel()->setContent('changed label');
$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--label"><label for="test-(...)">changed label</label></div><div class="p-form--input"><input type="text" id="test-\1" name="test" placeholder="Test" value="my text" /></div></div>~',
'~<div class="p-form__field"><div class="p-form__label"><label for="test-(...)">changed label</label></div><div class="p-form__input"><input type="text" id="test-\1" name="test" placeholder="Test" value="my text" /></div></div>~',
$text->getDecorator()->render()
);
}
Expand All @@ -35,7 +35,7 @@ public function testElementOrder()
$text->setValue('my text');
$text->getDecorator()->setElementOrder([DataHandlerDecorator::INPUT, DataHandlerDecorator::LABEL]);
$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--input"><input type="text" id="(test-...)" name="test" placeholder="Test" value="my text" /></div><div class="p-form--label"><label for="\1">Test</label></div></div>~',
'~<div class="p-form__field"><div class="p-form__input"><input type="text" id="(test-...)" name="test" placeholder="Test" value="my text" /></div><div class="p-form__label"><label for="\1">Test</label></div></div>~',
$text->getDecorator()->render()
);
}
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testHidden()
$text->setName('text');
$text->setDecorator($dec);
$this->assertRegExp(
'~<div class="p-form-field"><div class="p-form--label"><label for="(text-...)">Text</label></div><div class="p-form--input"><input type="hidden" id="\1" name="text" /></div></div>~',
'~<div class="p-form__field"><div class="p-form__label"><label for="(text-...)">Text</label></div><div class="p-form__input"><input type="hidden" id="\1" name="text" /></div></div>~',
$text->getDecorator()->render()
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Decorators/FormCustomDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testCustomDecorator()
$this->assertContains('placeholder="Email" value="[email protected]"', $output);
$this->assertContains('placeholder="Name" value="Mr Test"', $output);
$this->assertContains('<div class="err"></div>', $output);
$this->assertContains('<div class="inp"><div class="p-form--input">', $output);
$this->assertContains('<div class="lbl"><div class="p-form--label">', $output);
$this->assertContains('<div class="inp"><div class="p-form__input">', $output);
$this->assertContains('<div class="lbl"><div class="p-form__label">', $output);
}
}

0 comments on commit b211aec

Please sign in to comment.