示例#1
0
 protected function setUp()
 {
     parent::setUp();
     $this->fieldStorage = FieldStorageConfig::create(array('field_name' => strtolower($this->randomMachineName()), 'entity_type' => 'contact_message', 'type' => 'text'));
     $this->fieldStorage->save();
     ContactForm::create(['id' => 'contact_message', 'label' => 'Test contact form'])->save();
     FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => 'contact_message'])->save();
     $this->container->get('views.views_data')->clear();
 }
示例#2
0
 public function createForm(&$bundle_info)
 {
     if (!\Drupal::entityQuery('contact_form')->condition('id', $bundle_info['id'])->execute()) {
         $form_type = ContactForm::create(array('id' => $bundle_info['id'], 'label' => ucwords(str_replace('_', ' ', $bundle_info['id'])), 'type' => "contact_form"))->save();
         \Drupal::logger('clutch:workflow')->notice('Create bundle @bundle', array('@bundle' => $bundle_info, 'form' => $form_type));
         $this->createFields($bundle_info);
         $this->removeDefaultFormFields($bundle_info);
     }
 }
 /**
  * Tests deleting a contact form entity via a configuration import.
  *
  * @see \Drupal\Core\Entity\Event\BundleConfigImportValidate
  */
 public function testDeleteThroughImport()
 {
     $contact_form = ContactForm::create(['id' => 'test']);
     $contact_form->save();
     $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
     // Set up the ConfigImporter object for testing.
     $storage_comparer = new StorageComparer($this->container->get('config.storage.sync'), $this->container->get('config.storage'), $this->container->get('config.manager'));
     $config_importer = new ConfigImporter($storage_comparer->createChangelist(), $this->container->get('event_dispatcher'), $this->container->get('config.manager'), $this->container->get('lock'), $this->container->get('config.typed'), $this->container->get('module_handler'), $this->container->get('module_installer'), $this->container->get('theme_handler'), $this->container->get('string_translation'));
     // Delete the contact message in sync.
     $sync = $this->container->get('config.storage.sync');
     $sync->delete($contact_form->getConfigDependencyName());
     // Import.
     $config_importer->reset()->import();
     $this->assertNull(ContactForm::load($contact_form->id()), 'The contact form has been deleted.');
 }
 /**
  * Tests adding paragraphs in contact forms.
  */
 public function testContactForm()
 {
     $this->loginAsAdmin(['administer contact forms', 'access site-wide contact form']);
     // Add a paragraph type.
     $this->addParagraphsType('paragraphs_contact');
     // Create a contact form.
     $contact_form = ContactForm::create(['id' => 'test_contact_form']);
     $contact_form->save();
     // Add a paragraphs field to the contact form.
     $this->addParagraphsField($contact_form->id(), 'paragraphs', 'contact_message');
     // Add a paragraph to the contact form.
     $this->drupalGet('contact/test_contact_form');
     $this->drupalPostAjaxForm(NULL, [], 'paragraphs_paragraphs_contact_add_more');
     // Check that the paragraph is displayed.
     $this->assertText('Type: paragraphs_contact');
     $this->drupalPostAjaxForm(NULL, [], 'paragraphs_0_remove');
     $this->assertText('Deleted Paragraph: paragraphs_contact');
 }
 /**
  * Test enabling and disabling of page cache based on time limit settings.
  */
 public function testCacheContactForm()
 {
     // Create a Website feedback contact form.
     $feedback_form = ContactForm::create(['id' => 'feedback', 'label' => 'Website feedback', 'recipients' => [], 'reply' => '', 'weight' => 0]);
     $feedback_form->save();
     $contact_settings = \Drupal::configFactory()->getEditable('contact.settings');
     $contact_settings->set('default_form', 'feedback')->save();
     // Give anonymous users permission to view contact form.
     Role::load(RoleInterface::ANONYMOUS_ID)->grantPermission('access site-wide contact form')->save();
     // Prime the cache.
     $this->drupalGet('contact/feedback');
     // Test on cache header with time limit enabled, cache should miss.
     $this->drupalGet('contact/feedback');
     $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), '', 'Page was not cached.');
     // Disable time limit.
     $honeypot_config = \Drupal::configFactory()->getEditable('honeypot.settings')->set('time_limit', 0)->save();
     // Prime the cache.
     $this->drupalGet('contact/feedback');
     // Test on cache header with time limit disabled, cache should hit.
     $this->drupalGet('contact/feedback');
     $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
 }
 /**
  * Tests the contact forms listing for the translate operation.
  */
 public function doContactFormsListTest()
 {
     // Create a test contact form to decouple looking for translate operations
     // link so this does not test more than necessary.
     $contact_form = ContactForm::create(['id' => Unicode::strtolower($this->randomMachineName(16)), 'label' => $this->randomMachineName()]);
     $contact_form->save();
     // Get the contact form listing.
     $this->drupalGet('admin/structure/contact');
     $translate_link = 'admin/structure/contact/manage/' . $contact_form->id() . '/translate';
     // Test if the link to translate the contact form is on the page.
     $this->assertLinkByHref($translate_link);
     // Test if the link to translate actually goes to the translate page.
     $this->drupalGet($translate_link);
     $this->assertRaw('<th>' . t('Language') . '</th>');
 }
 public function testProtectContactForm()
 {
     $this->drupalLogin($this->adminUser);
     // Disable 'protect_all_forms'.
     $honeypot_config = \Drupal::configFactory()->getEditable('honeypot.settings')->set('protect_all_forms', FALSE)->save();
     // Create a Website feedback contact form.
     $feedback_form = ContactForm::create(['id' => 'feedback', 'label' => 'Website feedback', 'recipients' => [], 'reply' => '', 'weight' => 0]);
     $feedback_form->save();
     $contact_settings = \Drupal::configFactory()->getEditable('contact.settings');
     $contact_settings->set('default_form', 'feedback')->save();
     // Submit the admin form so we can verify the right forms are displayed.
     $this->drupalPostForm('admin/config/content/honeypot', ['form_settings[contact_message_feedback_form]' => TRUE], t('Save configuration'));
     $this->drupalLogin($this->webUser);
     $this->drupalGet('contact/feedback');
     $this->assertField('url', 'Honeypot field is added to Contact form.');
 }
示例#8
0
 /**
  * Test that tokens are properly created for an entity's base fields.
  */
 public function testBaseFieldTokens()
 {
     // Create a new contact_message entity and verify that tokens are generated
     // for its base fields. The contact_message entity type is used because it
     // provides no tokens by default.
     $contact_form = ContactForm::create(['id' => 'form_id']);
     $contact_form->save();
     $entity = Message::create(['contact_form' => 'form_id', 'uuid' => '123', 'langcode' => 'en', 'name' => 'Test name', 'mail' => 'Test mail', 'subject' => 'Test subject', 'message' => 'Test message', 'copy' => FALSE]);
     $entity->save();
     $this->assertTokens('contact_message', ['contact_message' => $entity], ['uuid' => Markup::create('123'), 'langcode' => Markup::create('English'), 'name' => Markup::create('Test name'), 'mail' => Markup::create('Test mail'), 'subject' => Markup::create('Test subject'), 'message' => Markup::create('Test message'), 'copy' => 'Off']);
     // Test the metadata of one of the tokens.
     $tokenService = \Drupal::service('token');
     $token_info = $tokenService->getTokenInfo('contact_message', 'subject');
     $this->assertEquals($token_info['name'], 'Subject');
     $this->assertEquals($token_info['description'], 'Text (plain) field.');
     $this->assertEquals($token_info['module'], 'token');
     // Verify that node entity type doesn't have a uid token.
     $this->assertNull($tokenService->getTokenInfo('node', 'uid'));
 }