You are here

function ViewsHandlersTest::test_views_break_phrase in Views (for Drupal 7) 7.3

Tests views_break_phrase function.

File

tests/views_handlers.test, line 95
Definition of ViewsHandlersTest.

Class

ViewsHandlersTest
Tests abstract handlers of views.

Code

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

  // check defaults.
  $this
    ->assertEqual($empty_stdclass, views_break_phrase('', $null));
  $handler = views_get_handler('node', 'title', 'argument');
  $this
    ->assertEqual($handler, views_break_phrase('', $handler));

  // 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,
  ), views_break_phrase("{$n1} {$n2}+{$n3}", $handler));
  $this
    ->assertEqual('or', $handler->operator);
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), views_break_phrase("{$n1}+{$n2}+{$n3}", $handler));
  $this
    ->assertEqual('or', $handler->operator);
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), views_break_phrase("{$n1} {$n2} {$n3}", $handler));
  $this
    ->assertEqual('or', $handler->operator);
  $this
    ->assertEqualValue(array(
    $n1,
    $n2,
    $n3,
  ), views_break_phrase("{$n1} {$n2}++{$n3}", $handler));
  $this
    ->assertEqual('or', $handler->operator);

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