public function UriTest::testValidation in Feeds 8.3
Tests validation.
File
- tests/
src/ Unit/ Element/ UriTest.php, line 32
Class
- UriTest
- @coversDefaultClass \Drupal\feeds\Element\Uri @group feeds
Namespace
Drupal\Tests\feeds\Unit\ElementCode
public function testValidation() {
$complete_form = [];
$form_state = new FormState();
$stream_wrapper_manager = new StreamWrapperManager();
$element_object = new Uri([], '', []);
$element = [
'#value' => ' public://test',
'#parents' => [
'element',
],
];
$element += $element_object
->getInfo();
Uri::validateUrl($element, $form_state, $complete_form, $stream_wrapper_manager);
$this
->assertSame('public://test', $form_state
->getValue('element'));
$element = [
'#value' => '',
'#parents' => [
'element',
],
];
$element += $element_object
->getInfo();
Uri::validateUrl($element, $form_state, $complete_form, $stream_wrapper_manager);
$this
->assertSame('', $form_state
->getValue('element'));
$element = [
'#value' => '@@',
'#parents' => [
'element',
],
];
$element += $element_object
->getInfo();
Uri::validateUrl($element, $form_state, $complete_form, $stream_wrapper_manager);
$this
->assertSame('@@', $form_state
->getValue('element'));
$this
->assertSame('The URI <em class="placeholder">@@</em> is not valid.', (string) $form_state
->getError($element));
$form_state
->clearErrors();
$element = [
'#value' => 'badscheme://foo',
'#parents' => [
'element',
],
'#allowed_schemes' => [
'public',
],
];
$element += $element_object
->getInfo();
Uri::validateUrl($element, $form_state, $complete_form, $stream_wrapper_manager);
$this
->assertSame('The scheme <em class="placeholder">badscheme</em> is invalid. Available schemes: public.', (string) $form_state
->getError($element));
}