function ConditionsFormTest::dataConditionsFormWidgets

Provides data for testConditionsFormWidgets().

Return value

array The test data array. The top level keys are free text but should be short and relate to the test case. The values are ordered arrays of test case data with elements that must appear in the following order:

  • Machine name of the condition being tested.
  • (optional) Required values to enter on the Context form. This is an associative array with keys equal to the field names and values equal to the required field values.
  • (optional) Values for fields that have defaults. This is an associative array with keys equal to the field names and values equal to the field values. These are used on the second edit, to alter the fields that have been saved with their default value.
  • (optional) Widget types we expect to see on the Context form. This is an associative array with keys equal to the field names as above, and values equal to expected widget type.
  • (optional) Names of fields for which the selector/direct input button needs pressing to 'data selection' before the field value is entered.

File

tests/src/Functional/ConditionsFormTest.php, line 169

Class

ConditionsFormTest
Tests that each Rules Condition can be edited.

Namespace

Drupal\Tests\rules\Functional

Code

public function dataConditionsFormWidgets() {
    // Instead of directly returning the full set of test data, create variable
    // $data to hold it. This allows for manipulation before the final return.
    $data = [
        // Data.
'1. Data comparison' => [
            // Machine name.
'rules_data_comparison',
            // Required values.
[
                'data' => 'node.title.value',
                'value' => 'node_unchanged.title.value',
            ],
            // Defaulted values.
[
                'operation' => 'contains',
            ],
            // Widgets.
[
                'data' => 'text-input',
                'operation' => 'text-input',
                'value' => 'text-input',
            ],
            // Selectors.
[
                'value',
            ],
        ],
        '2. Data is empty' => [
            'rules_data_is_empty',
            [
                'data' => 'node.title.value',
            ],
        ],
        '3. List contains' => [
            'rules_list_contains',
            [
                'list' => 'node.uid.entity.roles',
                'item' => 'abc',
            ],
            [],
            [
                'list' => 'textarea',
            ],
        ],
        '4. List count is' => [
            'rules_list_count_is',
            [
                'list' => 'node.uid.entity.roles',
                'value' => 2,
            ],
            [
                'operator' => '<=',
            ],
        ],
        '5. Text comparison - direct' => [
            'rules_text_comparison',
            [
                'text' => 'node.title.value',
                'match' => 'abc',
            ],
        ],
        '6. Text comparison - selector' => [
            'rules_text_comparison',
            [
                'text' => 'node.title.value',
                'match' => 'node.uid.entity.name.value',
            ],
            [
                'operator' => 'ends',
            ],
            [],
            [
                'match',
            ],
        ],
        // Entity.
'7. Entity has field' => [
            'rules_entity_has_field',
            [
                'entity' => 'node',
                'field' => 'login',
            ],
        ],
        '8. Entity is new' => [
            'rules_entity_is_new',
            [
                'entity' => 'node',
            ],
        ],
        '9. Entity is of bundle' => [
            'rules_entity_is_of_bundle',
            [
                'entity' => 'node',
                'type' => 'node',
                'bundle' => 'article',
            ],
        ],
        '10. Entity is of type' => [
            'rules_entity_is_of_type',
            [
                'entity' => 'node',
                'type' => 'path_alias',
            ],
        ],
        // Content.
'11. Node is of type' => [
            'rules_node_is_of_type',
            [
                'node' => 'node',
                'types' => 'article',
            ],
        ],
        '12. Node is promoted' => [
            'rules_node_is_promoted',
            [
                'node' => 'node',
            ],
        ],
        '13. Node is published' => [
            'rules_node_is_published',
            [
                'node' => 'node',
            ],
        ],
        '14. Node is sticky' => [
            'rules_node_is_sticky',
            [
                'node' => 'node',
            ],
        ],
        // Path.
'15. Path alias exists' => [
            'rules_path_alias_exists',
            [
                'alias' => '/abc',
            ],
            [
                'language' => 'und',
            ],
        ],
        '16. Path has alias' => [
            'rules_path_has_alias',
            [
                'path' => '/node/1',
            ],
            [
                'language' => 'en',
            ],
        ],
        // User.
'17. Entity field access' => [
            'rules_entity_field_access',
            [
                'entity' => 'node',
                'field' => 'timezone',
                'user' => '@user.current_user_context:current_user',
            ],
            [
                'operation' => 'edit',
            ],
        ],
        '18. User has role' => [
            'rules_user_has_role',
            [
                'user' => '@user.current_user_context:current_user',
                'roles' => 'test-editor',
            ],
            [
                'operation' => 'OR',
            ],
            [],
            [
                'user',
            ],
        ],
        '19. User is blocked' => [
            'rules_user_is_blocked',
            [
                'user' => '@user.current_user_context:current_user',
            ],
            [],
            [],
            [
                'user',
            ],
        ],
        // Ban.
'20. Ip is banned' => [
            'rules_ip_is_banned',
            [],
            [
                'ip' => '192.0.2.1',
            ],
        ],
    ];
    // Use unset $data['The key to remove']; to remove a temporarily unwanted
    // item, use return [$data['The key to test']]; to selectively test just one
    // item, or use return $data; to test everything.
    return $data;
}