You are here

function HandlerTest::testBreakPhrase in Views (for Drupal 7) 8.3

Tests Drupal\views\Plugin\views\HandlerBase::breakPhrase() function.

File

lib/Drupal/views/Tests/Handler/HandlerTest.php, line 143
Definition of Drupal\views\Tests\Handler\HandlerTest.

Class

HandlerTest
Tests abstract handlers of views.

Namespace

Drupal\views\Tests\Handler

Code

function testBreakPhrase() {
  $empty_stdclass = new \stdClass();
  $empty_stdclass->operator = 'or';
  $empty_stdclass->value = array();
  $null = NULL;

  // check defaults
  $this
    ->assertEqual($empty_stdclass, HandlerBase::breakPhrase('', $null));
  $handler = views_get_handler('node', 'title', 'argument');
  $this
    ->assertEqual($handler, HandlerBase::breakPhrase('', $handler), 'The breakPhrase() method works correctly.');

  // Generate three random numbers which can be used below;
  $n1 = rand(0, 100);
  $n2 = rand(0, 100);
  $n3 = rand(0, 100);

  // test ors
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), HandlerBase::breakPhrase("{$n1} {$n2}+{$n3}", $handler));
  $this
    ->assertEqual('or', $handler->operator);
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), HandlerBase::breakPhrase("{$n1}+{$n2}+{$n3}", $handler));
  $this
    ->assertEqual('or', $handler->operator);
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), HandlerBase::breakPhrase("{$n1} {$n2} {$n3}", $handler));
  $this
    ->assertEqual('or', $handler->operator);
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), HandlerBase::breakPhrase("{$n1} {$n2}++{$n3}", $handler));
  $this
    ->assertEqual('or', $handler->operator);

  // test ands.
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), HandlerBase::breakPhrase("{$n1},{$n2},{$n3}", $handler));
  $this
    ->assertEqual('and', $handler->operator);
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), HandlerBase::breakPhrase("{$n1},,{$n2},{$n3}", $handler));
  $this
    ->assertEqual('and', $handler->operator);
}