Backup of db before drupal security update
[yaffs-website] / web / core / modules / contact / tests / src / Kernel / Migrate / MigrateContactCategoryTest.php
1 <?php
2
3 namespace Drupal\Tests\contact\Kernel\Migrate;
4
5 use Drupal\contact\Entity\ContactForm;
6 use Drupal\contact\ContactFormInterface;
7 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
8
9 /**
10  * Migrate contact categories to contact.form.*.yml.
11  *
12  * @group contact_category
13  */
14 class MigrateContactCategoryTest extends MigrateDrupal6TestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['contact'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28     $this->executeMigration('contact_category');
29   }
30
31   /**
32    * Performs various assertions on a single contact form entity.
33    *
34    * @param string $id
35    *   The contact form ID.
36    * @param string $expected_label
37    *   The 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.
44    */
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());
53   }
54
55   /**
56    * The Drupal 6 and 7 contact categories to Drupal 8 migration.
57    */
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);
62
63     // Test there are no duplicated roles.
64     $contact_forms = [
65       'website_feedback1',
66       'some_other_category1',
67       'a_category_much_longer_than_thir1',
68     ];
69     $this->assertEmpty(ContactForm::loadMultiple($contact_forms));
70
71     /*
72      * Remove the map row for the Website feedback contact form so that it
73      * can be migrated again.
74      */
75     $id_map = $this->getMigration('contact_category')->getIdMap();
76     $id_map->delete(['cid' => '1']);
77     $this->executeMigration('contact_category');
78
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);
82   }
83
84 }