View source
<?php
namespace Drupal\Tests\contact\Kernel\Migrate;
use Drupal\contact\Entity\ContactForm;
use Drupal\contact\ContactFormInterface;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
class MigrateContactCategoryTest extends MigrateDrupal6TestBase {
protected static $modules = [
'contact',
];
protected function setUp() : void {
parent::setUp();
$this
->executeMigration('contact_category');
}
protected function assertEntity(string $id, string $expected_label, array $expected_recipients, string $expected_reply, int $expected_weight) : void {
$entity = ContactForm::load($id);
$this
->assertInstanceOf(ContactFormInterface::class, $entity);
$this
->assertSame($expected_label, $entity
->label());
$this
->assertSame($expected_recipients, $entity
->getRecipients());
$this
->assertSame($expected_reply, $entity
->getReply());
$this
->assertSame($expected_weight, $entity
->getWeight());
}
public function testContactCategory() {
$this
->assertEntity('website_feedback', 'Website feedback', [
'admin@example.com',
], '', 0);
$this
->assertEntity('some_other_category', 'Some other category', [
'test@example.com',
], 'Thanks for contacting us, we will reply ASAP!', 1);
$this
->assertEntity('a_category_much_longer_than_th', 'A category much longer than thirty two characters', [
'fortyninechars@example.com',
], '', 2);
$contact_forms = [
'website_feedback1',
'some_other_category1',
'a_category_much_longer_than_thir1',
];
$this
->assertEmpty(ContactForm::loadMultiple($contact_forms));
$id_map = $this
->getMigration('contact_category')
->getIdMap();
$id_map
->delete([
'cid' => '1',
]);
$this
->executeMigration('contact_category');
$this
->assertEntity('website_feedback1', 'Website feedback', [
'admin@example.com',
], '', 0);
}
}