function ViewsHandlersTest::test_views_break_phrase

Tests views_break_phrase function.

File

tests/views_handlers.test, line 102

Class

ViewsHandlersTest
Tests abstract handlers of views.

Code

public 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);
}