RoleTest.php in Mass Contact 8
File
tests/src/Kernel/Plugin/MassContact/GroupingMethod/RoleTest.php
View source
<?php
namespace Drupal\Tests\mass_contact\Kernel\Plugin\MassContact\GroupingMethod;
use Drupal\simpletest\UserCreationTrait;
use Drupal\Tests\mass_contact\Kernel\MassContactTestBase;
use Drupal\user\Entity\Role as UserRole;
use Drupal\user\RoleInterface;
class RoleTest extends MassContactTestBase {
use UserCreationTrait;
protected $recipients;
protected $roles;
protected $groupingManager;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
]);
foreach (range(1, 3) as $i) {
$rid = $this
->createRole([]);
$this->roles[$i] = UserRole::load($rid);
}
foreach (range(1, 10) as $i) {
$this->recipients[$i] = $this
->createUser([]);
$this->recipients[$i]
->addRole($this->roles[2]
->id());
if ($i == 4) {
$this->recipients[$i]
->block();
}
$this->recipients[$i]
->save();
}
$this->groupingManager = \Drupal::service('plugin.manager.mass_contact.grouping_method');
}
public function testGetRecipients() {
$config = [
'conjunction' => 'OR',
'categories' => [
RoleInterface::AUTHENTICATED_ID,
$this->roles[3]
->id(),
],
];
$instance = $this->groupingManager
->createInstance('role', $config);
$this
->assertEquals(9, count($instance
->getRecipients($config['categories'])));
$config['conjunction'] = 'AND';
$instance = $this->groupingManager
->createInstance('role', $config);
$this
->assertEmpty($instance
->getRecipients($config['categories']));
foreach ([
7,
9,
] as $uid) {
$this->recipients[$uid]
->addRole($this->roles[3]
->id());
$this->recipients[$uid]
->save();
}
$this->recipients[7]
->addRole($this->roles[1]
->id());
$this->recipients[7]
->save();
$instance = $this->groupingManager
->createInstance('role', $config);
$this
->assertEquals(2, count($instance
->getRecipients($config['categories'])));
$config['categories'] = [
$this->roles[3]
->id(),
$this->roles[1]
->id(),
];
$instance = $this->groupingManager
->createInstance('role', $config);
$this
->assertEquals(1, count($instance
->getRecipients($config['categories'])));
$config['conjunction'] = 'OR';
$instance = $this->groupingManager
->createInstance('role', $config);
$this
->assertEquals(2, count($instance
->getRecipients($config['categories'])));
}
}
Classes
Name |
Description |
RoleTest |
Tests the role grouping method plugin. |