class LdapAuthorizationProviderTest in Lightweight Directory Access Protocol (LDAP) 8.4
@coversDefaultClass \Drupal\ldap_authorization\Plugin\authorization\Provider\LDAPAuthorizationProvider @group authorization
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\ldap_authorization\Unit\LdapAuthorizationProviderTest
Expanded class hierarchy of LdapAuthorizationProviderTest
File
- ldap_authorization/
tests/ src/ Unit/ LdapAuthorizationProviderTest.php, line 16
Namespace
Drupal\Tests\ldap_authorization\UnitView source
class LdapAuthorizationProviderTest extends UnitTestCase {
/**
* Provider plugin.
*
* @var \Drupal\ldap_authorization\Plugin\authorization\Provider\LDAPAuthorizationProvider
*/
protected $providerPlugin;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->providerPlugin = $this
->getMockBuilder(LDAPAuthorizationProvider::class)
->setMethods(NULL)
->disableOriginalConstructor()
->getMock();
}
/**
* Test regex validation().
*/
public function testValidateRowForm() : void {
$form_state = new FormState();
$mappings = [
0 => [
'provider_mappings' => [
'is_regex' => 1,
'query' => 'example',
],
],
1 => [
'provider_mappings' => [
'is_regex' => 1,
'query' => '/.*/',
],
],
2 => [
'provider_mappings' => [
'is_regex' => 0,
'query' => '/.*/',
],
],
];
$form_state
->setUserInput($mappings);
$sub_form_state = new SubFormState($form_state, [
'provider_config',
]);
$form = [];
$this->providerPlugin
->validateRowForm($form, $sub_form_state);
self::assertEquals([], $sub_form_state
->getErrors());
// @todo Still needs more useful assertions here.
}
/**
* Test the filter proposal.
*/
public function testFilterProposal() : void {
// Example of groups defined in.
$input = [
'cn=students',
];
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => 'cn=students',
'is_regex' => FALSE,
]));
$input = [
'cn=students,ou=groups,dc=hogwarts,dc=edu',
'cn=gryffindor,ou=groups,dc=hogwarts,dc=edu',
'cn=users,ou=groups,dc=hogwarts,dc=edu',
];
self::assertCount(0, $this->providerPlugin
->filterProposals($input, [
'query' => 'cn=students',
'is_regex' => FALSE,
]));
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => 'cn=students,ou=groups,dc=hogwarts,dc=edu',
'is_regex' => FALSE,
]));
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => 'CN=students,ou=groups,dc=hogwarts,dc=edu',
'is_regex' => FALSE,
]));
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => '/cn=students/i',
'is_regex' => TRUE,
]));
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => '/CN=students/i',
'is_regex' => TRUE,
]));
// Get only one of the values.
$input = [
'cn=users,ou=gryffindor,ou=slytherin,ou=ravenclaw,dc=hogwarts,dc=edu',
];
$output = $this->providerPlugin
->filterProposals($input, [
'query' => '/(?<=ou=).+?[^\\,]*/i',
'is_regex' => TRUE,
]);
self::assertEquals('gryffindor', $output[0]);
self::assertCount(1, $output);
$input = [
'memberOf=students,ou=groups,dc=hogwarts,dc=edu',
];
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => 'memberOf=students,ou=groups,dc=hogwarts,dc=edu',
'is_regex' => FALSE,
]));
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => 'memberof=students,ou=groups,dc=hogwarts,dc=edu',
'is_regex' => FALSE,
]));
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => '/^memberof=students/i',
'is_regex' => TRUE,
]));
self::assertCount(1, $this->providerPlugin
->filterProposals($input, [
'query' => '/^memberOf=students/i',
'is_regex' => TRUE,
]));
self::assertCount(0, $this->providerPlugin
->filterProposals($input, [
'query' => '/^emberOf=students/i',
'is_regex' => TRUE,
]));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LdapAuthorizationProviderTest:: |
protected | property | Provider plugin. | |
LdapAuthorizationProviderTest:: |
public | function |
Overrides UnitTestCase:: |
|
LdapAuthorizationProviderTest:: |
public | function | Test the filter proposal. | |
LdapAuthorizationProviderTest:: |
public | function | Test regex validation(). | |
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. |