MassContactCategoryTest.php in Mass Contact 8
File
tests/src/Kernel/Entity/MassContactCategoryTest.php
View source
<?php
namespace Drupal\Tests\mass_contact\Kernel\Entity;
use Drupal\simpletest\UserCreationTrait;
use Drupal\Tests\mass_contact\Kernel\CategoryCreationTrait;
use Drupal\Tests\mass_contact\Kernel\MassContactTestBase;
use Drupal\user\Entity\Role;
class MassContactCategoryTest extends MassContactTestBase {
use CategoryCreationTrait;
use UserCreationTrait;
protected $roles;
protected function setUp() {
parent::setUp();
foreach ([
'foo',
'bar',
'baz',
] as $rid) {
$this->roles[$rid] = Role::load($this
->createRole([], $rid, ucfirst($rid)));
}
}
public function testCrud() {
$category = $this
->createCategory();
$grouping = $category
->getGroupingCategories('role');
$this
->assertFalse($grouping);
$recipients = [
'role' => [
'categories' => [
'foo',
'bar',
],
'conjunction' => 'AND',
],
];
$category
->setRecipients($recipients);
$this
->assertEquals($recipients, $category
->getRecipients());
$this
->assertFalse($category
->getGroupingCategories('foo'));
$grouping = $category
->getGroupingCategories('role');
$this
->assertEquals([
'foo',
'bar',
], $grouping
->getCategories());
$this
->assertEquals('Roles: <em class="placeholder">Foo, Bar</em>', $grouping
->displayCategories([
'foo',
'bar',
]));
}
}