views_user_argument_validate.test

Definition of ViewsUserArgumentValidate.

File

tests/user/views_user_argument_validate.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsUserArgumentValidate.
  5. */
  6. /**
  7. * Tests views user argument argument handler.
  8. */
  9. class ViewsUserArgumentValidate extends ViewsSqlTest {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Tests user argument validator',
  13. 'description' => 'Tests user argument validator',
  14. 'group' => 'Views Plugins',
  15. );
  16. }
  17. function setUp() {
  18. parent::setUp('views');
  19. $this->account = $this->drupalCreateUser();
  20. }
  21. function testArgumentValidateUserUid() {
  22. $account = $this->account;
  23. // test 'uid' case
  24. $view = $this->view_argument_validate_user('uid');
  25. $view->set_display('default');
  26. $view->pre_execute();
  27. $view->init_handlers();
  28. $this->assertTrue($view->argument['null']->validate_arg($account->uid));
  29. // Reset safed argument validation.
  30. $view->argument['null']->argument_validated = NULL;
  31. // Fail for a string variable since type is 'uid'
  32. $this->assertFalse($view->argument['null']->validate_arg($account->name));
  33. // Reset safed argument validation.
  34. $view->argument['null']->argument_validated = NULL;
  35. // Fail for a valid numeric, but for a user that doesn't exist
  36. $this->assertFalse($view->argument['null']->validate_arg(32));
  37. }
  38. function testArgumentValidateUserName() {
  39. $account = $this->account;
  40. // test 'name' case
  41. $view = $this->view_argument_validate_user('name');
  42. $view->set_display('default');
  43. $view->pre_execute();
  44. $view->init_handlers();
  45. $this->assertTrue($view->argument['null']->validate_arg($account->name));
  46. // Reset safed argument validation.
  47. $view->argument['null']->argument_validated = NULL;
  48. // Fail for a uid variable since type is 'name'
  49. $this->assertFalse($view->argument['null']->validate_arg($account->uid));
  50. // Reset safed argument validation.
  51. $view->argument['null']->argument_validated = NULL;
  52. // Fail for a valid string, but for a user that doesn't exist
  53. $this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
  54. }
  55. function testArgumentValidateUserEither() {
  56. $account = $this->account;
  57. // test 'either' case
  58. $view = $this->view_argument_validate_user('either');
  59. $view->set_display('default');
  60. $view->pre_execute();
  61. $view->init_handlers();
  62. $this->assertTrue($view->argument['null']->validate_arg($account->name));
  63. // Reset safed argument validation.
  64. $view->argument['null']->argument_validated = NULL;
  65. // Fail for a uid variable since type is 'name'
  66. $this->assertTrue($view->argument['null']->validate_arg($account->uid));
  67. // Reset safed argument validation.
  68. $view->argument['null']->argument_validated = NULL;
  69. // Fail for a valid string, but for a user that doesn't exist
  70. $this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
  71. // Reset safed argument validation.
  72. $view->argument['null']->argument_validated = NULL;
  73. // Fail for a valid uid, but for a user that doesn't exist
  74. $this->assertFalse($view->argument['null']->validate_arg(32));
  75. }
  76. function view_argument_validate_user($argtype) {
  77. $view = new view;
  78. $view->name = 'view_argument_validate_user';
  79. $view->description = '';
  80. $view->tag = '';
  81. $view->view_php = '';
  82. $view->base_table = 'node';
  83. $view->is_cacheable = FALSE;
  84. $view->api_version = 2;
  85. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  86. /* Display: Master */
  87. $handler = $view->new_display('default', 'Master', 'default');
  88. $handler->display->display_options['access']['type'] = 'none';
  89. $handler->display->display_options['cache']['type'] = 'none';
  90. $handler->display->display_options['exposed_form']['type'] = 'basic';
  91. $handler->display->display_options['pager']['type'] = 'full';
  92. $handler->display->display_options['style_plugin'] = 'default';
  93. $handler->display->display_options['row_plugin'] = 'fields';
  94. /* Argument: Global: Null */
  95. $handler->display->display_options['arguments']['null']['id'] = 'null';
  96. $handler->display->display_options['arguments']['null']['table'] = 'views';
  97. $handler->display->display_options['arguments']['null']['field'] = 'null';
  98. $handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
  99. $handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
  100. $handler->display->display_options['arguments']['null']['validate']['type'] = 'user';
  101. $handler->display->display_options['arguments']['null']['validate_options']['type'] = $argtype;
  102. $handler->display->display_options['arguments']['null']['must_not_be'] = 0;
  103. return $view;
  104. }
  105. }