class CrmCoreUserSyncRelationRulesTest in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_user_sync/tests/src/Unit/CrmCoreUserSyncRelationRulesTest.php \Drupal\Tests\crm_core_user_sync\Unit\CrmCoreUserSyncRelationRulesTest
Test CrmCoreUserSyncRelationRules service.
@property \Drupal\crm_core_user_sync\CrmCoreUserSyncRelationRules rulesService @group crm_core_user_sync @coversDefaultClass \Drupal\crm_core_user_sync\CrmCoreUserSyncRelationRules
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\crm_core_user_sync\Unit\CrmCoreUserSyncRelationRulesTest
Expanded class hierarchy of CrmCoreUserSyncRelationRulesTest
File
- modules/
crm_core_user_sync/ tests/ src/ Unit/ CrmCoreUserSyncRelationRulesTest.php, line 19
Namespace
Drupal\Tests\crm_core_user_sync\UnitView source
class CrmCoreUserSyncRelationRulesTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$rules = [];
$rules[] = [
'role' => 'customer',
'contact_type' => 'customer',
'enabled' => TRUE,
'weight' => 1,
];
$rules[] = [
'role' => 'authenticated',
'contact_type' => 'individual',
'enabled' => TRUE,
'weight' => 10,
];
$config = $this
->getMockBuilder(ImmutableConfig::class)
->disableOriginalConstructor()
->getMock();
$config
->expects($this
->once())
->method('get')
->with('rules')
->willReturn($rules);
$config_name = 'crm_core_user_sync.settings';
$configFactory = $this
->createMock(ConfigFactoryInterface::class);
$configFactory
->expects($this
->once())
->method('get')
->with($config_name)
->willReturn($config);
$this->rulesService = new CrmCoreUserSyncRelationRules($configFactory, $config_name);
}
/**
* Tests CrmCoreUserSyncRelationRules service.
*/
public function testCrmCoreUserSyncRelationRulesService() {
$account_authenticated = $this
->createMock(UserInterface::class);
$account_authenticated
->expects($this
->any())
->method('hasRole')
->willReturnMap([
[
'authenticated',
TRUE,
],
[
'customer',
FALSE,
],
]);
$account_customer = $this
->createMock(UserInterface::class);
$account_customer
->expects($this
->any())
->method('hasRole')
->willReturnMap([
[
'authenticated',
FALSE,
],
[
'customer',
TRUE,
],
]);
$contact_individual = $this
->createMock(IndividualInterface::class);
$contact_individual
->expects($this
->any())
->method('bundle')
->willReturn('individual');
$contact_customer = $this
->createMock(IndividualInterface::class);
$contact_customer
->expects($this
->any())
->method('bundle')
->willReturn('customer');
$this
->assertFalse($this->rulesService
->valid($account_customer, $contact_individual), 'Individual contact cannot be related to customer user.');
$this
->assertFalse($this->rulesService
->valid($account_authenticated, $contact_customer), 'Customer contact can be related to authenticated user.');
$this
->assertTrue($this->rulesService
->valid($account_authenticated, $contact_individual), 'Individual contact can be related to authenticated user.');
$this
->assertTrue($this->rulesService
->valid($account_customer, $contact_customer), 'Customer contact can be related to customer user.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CrmCoreUserSyncRelationRulesTest:: |
protected | function |
Overrides UnitTestCase:: |
|
CrmCoreUserSyncRelationRulesTest:: |
public | function | Tests CrmCoreUserSyncRelationRules service. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |