You are here

public function ConditionsFormTest::dataConditionsFormWidgets in Rules 8.3

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) Values to enter on the Context form. This is an associative array with keys equal to the field names and values equal to the field values.
  • (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 148

Class

ConditionsFormTest
Tests that each Rules Condition can be editted.

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 comparison' => [
      // Machine name.
      'rules_data_comparison',
      // Values.
      [
        'data' => 'node.title.value',
        'operation' => '=this=is-not-validated=yet=',
        'value' => 'node_unchanged.title.value',
      ],
      // Widgets.
      [
        'data' => 'text-input',
        'operation' => 'text-input',
        'value' => 'text-input',
      ],
      // Selectors.
      [
        'value',
      ],
    ],
    'Data is empty' => [
      'rules_data_is_empty',
      [
        'data' => 'node.title.value',
      ],
    ],
    'List contains' => [
      'rules_list_contains',
      [
        'list' => 'node.uid.entity.roles',
        'item' => 'abc',
      ],
      [
        'list' => 'textarea',
      ],
    ],
    'List Count' => [
      'rules_list_count_is',
      [
        'list' => 'node.uid.entity.roles',
        'operator' => 'not * validated * yet',
        'value' => 2,
      ],
    ],
    'Entity has field' => [
      'rules_entity_has_field',
      [
        'entity' => 'node',
        'field' => 'abc',
      ],
    ],
    'Entity is new' => [
      'rules_entity_is_new',
      [
        'entity' => 'node',
      ],
    ],
    'Entity is bundle' => [
      'rules_entity_is_of_bundle',
      [
        'entity' => 'node',
        'type' => 'node',
        'bundle' => 'article',
      ],
    ],
    'Entity is type' => [
      'rules_entity_is_of_type',
      [
        'entity' => 'node',
        'type' => 'article',
      ],
    ],
    'Node is type' => [
      'rules_node_is_of_type',
      [
        'node' => 'node',
        'types' => 'article',
      ],
    ],
    'Node is promoted' => [
      'rules_node_is_promoted',
      [
        'node' => 'node',
      ],
    ],
    'Node is published' => [
      'rules_node_is_published',
      [
        'node' => 'node',
      ],
    ],
    'Node is sticky' => [
      'rules_node_is_sticky',
      [
        'node' => 'node',
      ],
    ],
    'Path alias exists' => [
      'rules_path_alias_exists',
      [
        'alias' => '/abc',
      ],
    ],
    'Path has alias' => [
      'rules_path_has_alias',
      [
        'path' => '/node/1',
      ],
    ],
    'Text comparison - direct' => [
      'rules_text_comparison',
      [
        'text' => 'node.title.value',
        'match' => 'abc',
      ],
    ],
    'Text comparison - selector' => [
      'rules_text_comparison',
      [
        'text' => 'node.title.value',
        'match' => 'node.uid.entity.name.value',
      ],
      [],
      [
        'match',
      ],
    ],
    'Entity field access' => [
      'rules_entity_field_access',
      [
        'entity' => 'node',
        'field' => 'abc',
        'user' => '@user.current_user_context:current_user',
      ],
    ],
    'Uer has role' => [
      'rules_user_has_role',
      [
        'user' => '@user.current_user_context:current_user',
        'roles' => 'Developer',
      ],
    ],
    'User is blocked' => [
      'rules_user_is_blocked',
      [
        'user' => '@user.current_user_context:current_user',
      ],
    ],
    '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;
}