X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fsrc%2FFunctional%2FEmail%2FEmailFieldTest.php;fp=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fsrc%2FFunctional%2FEmail%2FEmailFieldTest.php;h=76a167d117bec075f5ce5bc4a2453d06b3016ac8;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/field/tests/src/Functional/Email/EmailFieldTest.php b/web/core/modules/field/tests/src/Functional/Email/EmailFieldTest.php new file mode 100644 index 000000000..76a167d11 --- /dev/null +++ b/web/core/modules/field/tests/src/Functional/Email/EmailFieldTest.php @@ -0,0 +1,106 @@ +drupalLogin($this->drupalCreateUser([ + 'view test entity', + 'administer entity_test content', + 'administer content types', + ])); + } + + /** + * Tests email field. + */ + public function testEmailField() { + // Create a field with settings to validate. + $field_name = mb_strtolower($this->randomMachineName()); + $this->fieldStorage = FieldStorageConfig::create([ + 'field_name' => $field_name, + 'entity_type' => 'entity_test', + 'type' => 'email', + ]); + $this->fieldStorage->save(); + $this->field = FieldConfig::create([ + 'field_storage' => $this->fieldStorage, + 'bundle' => 'entity_test', + ]); + $this->field->save(); + + // Create a form display for the default form mode. + entity_get_form_display('entity_test', 'entity_test', 'default') + ->setComponent($field_name, [ + 'type' => 'email_default', + 'settings' => [ + 'placeholder' => 'example@example.com', + ], + ]) + ->save(); + // Create a display for the full view mode. + entity_get_display('entity_test', 'entity_test', 'full') + ->setComponent($field_name, [ + 'type' => 'email_mailto', + ]) + ->save(); + + // Display creation form. + $this->drupalGet('entity_test/add'); + $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget found.'); + $this->assertRaw('placeholder="example@example.com"'); + + // Submit a valid email address and ensure it is accepted. + $value = 'test@example.com'; + $edit = [ + "{$field_name}[0][value]" => $value, + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); + $id = $match[1]; + $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); + $this->assertRaw($value); + + // Verify that a mailto link is displayed. + $entity = EntityTest::load($id); + $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full'); + $content = $display->build($entity); + $rendered_content = (string) \Drupal::service('renderer')->renderRoot($content); + $this->assertContains('href="mailto:test@example.com"', $rendered_content); + } + +}