summaryrefslogtreecommitdiff
path: root/sites/all/modules/views/tests/handlers/views_handler_argument_null.test
blob: e8650a3837a72b9c7592b70ed36d38b2caf6f20b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php

/**
 * @file
 * Definition of ViewsHandlerArgumentNullTest.
 */

/**
 * Tests the core views_handler_argument_null handler.
 */
class ViewsHandlerArgumentNullTest extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Argument: Null',
      'description' => 'Test the core views_handler_argument_null handler.',
      'group' => 'Views Handlers',
    );
  }

  function viewsData() {
    $data = parent::viewsData();
    $data['views_test']['id']['argument']['handler'] = 'views_handler_argument_null';

    return $data;
  }

  public function testAreaText() {
    // Test validation
    $view = $this->getBasicView();

    // Add a null argument.
    $string = $this->randomString();
    $view->display['default']->handler->override_option('arguments', array(
      'null' => array(
        'id' => 'null',
        'table' => 'views',
        'field' => 'null',
      ),
    ));

    $this->executeView($view);

    // Make sure that the argument is not validated yet.
    unset($view->argument['null']->argument_validated);
    $this->assertTrue($view->argument['null']->validate_arg(26));
    // test must_not_be option.
    unset($view->argument['null']->argument_validated);
    $view->argument['null']->options['must_not_be'] = TRUE;
    $this->assertFalse($view->argument['null']->validate_arg(26), 'must_not_be returns FALSE, if there is an argument');
    unset($view->argument['null']->argument_validated);
    $this->assertTrue($view->argument['null']->validate_arg(NULL), 'must_not_be returns TRUE, if there is no argument');

    // Test execution.
    $view = $this->getBasicView();

    // Add a argument, which has null as handler.
    $string = $this->randomString();
    $view->display['default']->handler->override_option('arguments', array(
      'id' => array(
        'id' => 'id',
        'table' => 'views_test',
        'field' => 'id',
      ),
    ));

    $this->executeView($view, array(26));

    // The argument should be ignored, so every result should return.
    $this->assertEqual(5, count($view->result));
  }

}