3 namespace Drupal\Tests\contact\Kernel\Migrate;
5 use Drupal\contact\Entity\ContactForm;
6 use Drupal\contact\ContactFormInterface;
7 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
10 * Migrate contact categories to contact.form.*.yml.
12 * @group contact_category
14 class MigrateContactCategoryTest extends MigrateDrupal6TestBase {
21 public static $modules = ['contact'];
26 protected function setUp() {
28 $this->executeMigration('contact_category');
32 * Performs various assertions on a single contact form entity.
35 * The contact form ID.
36 * @param string $expected_label
38 * @param string[] $expected_recipients
39 * The recipient e-mail addresses the form should have.
40 * @param string $expected_reply
41 * The expected reply message.
42 * @param int $expected_weight
43 * The contact form's expected weight.
45 protected function assertEntity($id, $expected_label, array $expected_recipients, $expected_reply, $expected_weight) {
46 /** @var \Drupal\contact\ContactFormInterface $entity */
47 $entity = ContactForm::load($id);
48 $this->assertTrue($entity instanceof ContactFormInterface);
49 $this->assertIdentical($expected_label, $entity->label());
50 $this->assertIdentical($expected_recipients, $entity->getRecipients());
51 $this->assertIdentical($expected_reply, $entity->getReply());
52 $this->assertIdentical($expected_weight, $entity->getWeight());
56 * The Drupal 6 and 7 contact categories to Drupal 8 migration.
58 public function testContactCategory() {
59 $this->assertEntity('website_feedback', 'Website feedback', ['admin@example.com'], '', 0);
60 $this->assertEntity('some_other_category', 'Some other category', ['test@example.com'], 'Thanks for contacting us, we will reply ASAP!', 1);
61 $this->assertEntity('a_category_much_longer_than_thir', 'A category much longer than thirty two characters', ['fortyninechars@example.com'], '', 2);
63 // Test there are no duplicated roles.
66 'some_other_category1',
67 'a_category_much_longer_than_thir1',
69 $this->assertEmpty(ContactForm::loadMultiple($contact_forms));
72 * Remove the map row for the Website feedback contact form so that it
73 * can be migrated again.
75 $id_map = $this->getMigration('contact_category')->getIdMap();
76 $id_map->delete(['cid' => '1']);
77 $this->executeMigration('contact_category');
79 // Test there is a duplicate Website feedback form.
80 $contact_form = ContactForm::load('website_feedback1');
81 $this->assertEntity('website_feedback1', 'Website feedback', ['admin@example.com'], '', 0);