You are here

public function QueryTest::match in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/modules/views_test_data/src/Plugin/views/query/QueryTest.php \Drupal\views_test_data\Plugin\views\query\QueryTest::match()

Check a single condition for a single element.

Parameters

array $element: The element which should be checked.

array $condition: An associative array containing:

  • field: The field to by, for example id.
  • value: The expected value of the element.
  • operator: The operator to compare the element value with the expected value.

Return value

bool Returns whether the condition matches with the element.

1 call to QueryTest::match()
QueryTest::execute in core/modules/views/tests/modules/views_test_data/src/Plugin/views/query/QueryTest.php
Executes the query and fills the associated view object with according values.

File

core/modules/views/tests/modules/views_test_data/src/Plugin/views/query/QueryTest.php, line 133

Class

QueryTest
Defines a query test plugin.

Namespace

Drupal\views_test_data\Plugin\views\query

Code

public function match($element, $condition) {
  $value = $element[$condition['field']];
  switch ($condition['operator']) {
    case '=':
      return $value == $condition['value'];
    case 'IN':
      return in_array($value, $condition['value']);
  }
  return FALSE;
}