class AgreementTest in Agreement 8.2
Same name and namespace in other branches
- 3.0.x tests/src/Unit/Entity/AgreementTest.php \Drupal\Tests\agreement\Unit\Entity\AgreementTest
Tests methods on the agreement entity.
@group agreement
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\agreement\Unit\Entity\AgreementTest
Expanded class hierarchy of AgreementTest
File
- tests/
src/ Unit/ Entity/ AgreementTest.php, line 13
Namespace
Drupal\Tests\agreement\Unit\EntityView source
class AgreementTest extends UnitTestCase {
/**
* Default agreement settings from agreement.agreement.default.
*
* @todo Add visibility in Drupal 9 when PHP 5 is non-supported.
*
* @internal
*/
const DEFAULT_AGREEMENT_SETTINGS = [
'visibility' => [
'settings' => 0,
'pages' => [],
],
'roles' => [
'authenticated',
],
'frequency' => -1,
'title' => 'Our Agreement',
'checkbox' => 'I agree.',
'submit' => 'Submit',
'success' => 'Thank you for accepting our agreement.',
'revoked' => 'You have successfully revoked your acceptance of our agreement.',
'failure' => 'You must accept our agreement to continue.',
'destination' => '',
'recipient' => '',
'reset_date' => 0,
'format' => 'plain_text',
];
/**
* Asserts that settings are populated.
*
* @param array $expected
* The expected output.
* @param array|null $settings
* The configuration settings.
*
* @dataProvider settingsProvider
*/
public function testGetSettings(array $expected, $settings) {
$agreement = new Agreement([
'id' => 'test',
'label' => 'Test',
'path' => '/agreement',
'agreement' => 'Agree',
'settings' => $settings,
], 'agreement');
$this
->assertArrayEquals($expected, $agreement
->getSettings());
}
/**
* Asserts the frequency timestamp based on reset_date and frequency.
*
* @param int $lessThan
* The expected value to be equal to or less than. This is not the exact
* value because it changes by the second.
* @param array|null $settings
* The settings to use.
*
* @dataProvider frequencyTimestampProvider
*/
public function testGetAgreementFrequencyTimestamp($lessThan, $settings) {
$agreement = new Agreement([
'id' => 'test',
'label' => 'Test',
'path' => '/agreement',
'agreement' => 'Agree',
'settings' => $settings,
], 'agreement');
$this
->assertLessThanOrEqual($lessThan, $agreement
->getAgreementFrequencyTimestamp());
}
/**
* Provides various settings and expected values.
*
* @return array
* An array of test arguments.
*/
public function frequencyTimestampProvider() {
$defaults = Agreement::getDefaultSettings();
$no_reset_date = self::DEFAULT_AGREEMENT_SETTINGS;
unset($no_reset_date['reset_date']);
$frequency_set = self::DEFAULT_AGREEMENT_SETTINGS;
$frequency_set['frequency'] = 3600;
return [
'no settings provided' => [
0,
$defaults,
],
'default agreement' => [
0,
self::DEFAULT_AGREEMENT_SETTINGS,
],
'no reset date' => [
0,
$no_reset_date,
],
'frequency > reset_date' => [
time(),
$frequency_set,
],
];
}
/**
* Provides various settings arrays for tests.
*
* @return array
* An array of test arguments.
*/
public function settingsProvider() {
$defaults = Agreement::getDefaultSettings();
$no_reset_date = self::DEFAULT_AGREEMENT_SETTINGS;
unset($no_reset_date['reset_date']);
return [
'no settings provided' => [
$defaults,
NULL,
],
'empty settings provided' => [
$defaults,
[],
],
'default agreement' => [
self::DEFAULT_AGREEMENT_SETTINGS,
self::DEFAULT_AGREEMENT_SETTINGS,
],
'no reset date' => [
self::DEFAULT_AGREEMENT_SETTINGS,
$no_reset_date,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AgreementTest:: |
constant | Default agreement settings from agreement.agreement.default. | ||
AgreementTest:: |
public | function | Provides various settings and expected values. | |
AgreementTest:: |
public | function | Provides various settings arrays for tests. | |
AgreementTest:: |
public | function | Asserts the frequency timestamp based on reset_date and frequency. | |
AgreementTest:: |
public | function | Asserts that settings are populated. | |
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. | |
UnitTestCase:: |
protected | function | 340 |