views_handler_argument_comment_user_uid.test 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @file
  4. * Definition of viewsHandlerArgumentCommentUserUidTest.
  5. */
  6. /**
  7. * Tests the argument_comment_user_uid handler.
  8. */
  9. class viewsHandlerArgumentCommentUserUidTest extends ViewsSqlTest {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Tests handler argument_comment_user_uid',
  13. 'description' => 'Tests the user posted or commented argument handler',
  14. 'group' => 'Views Modules',
  15. );
  16. }
  17. /**
  18. * Post comment.
  19. *
  20. * @param $node
  21. * Node to post comment on.
  22. * @param $comment
  23. * Comment to save
  24. */
  25. function postComment($node, $comment = array()) {
  26. $comment += array(
  27. 'uid' => $this->loggedInUser->uid,
  28. 'nid' => $node->nid,
  29. 'cid' => '',
  30. 'pid' => '',
  31. );
  32. return comment_save((object) $comment);
  33. }
  34. function setUp() {
  35. parent::setUp();
  36. // Add two users, create a node with the user1 as author and another node with user2 as author.
  37. // For the second node add a comment from user1.
  38. $this->account = $this->drupalCreateUser();
  39. $this->account2 = $this->drupalCreateUser();
  40. $this->drupalLogin($this->account);
  41. $this->node_user_posted = $this->drupalCreateNode();
  42. $this->node_user_commented = $this->drupalCreateNode(array('uid' => $this->account2->uid));
  43. $this->postComment($this->node_user_commented);
  44. }
  45. function testCommentUserUidTest() {
  46. $view = $this->view_comment_user_uid();
  47. $this->executeView($view, array($this->account->uid));
  48. $resultset = array(
  49. array(
  50. 'nid' => $this->node_user_posted->nid,
  51. ),
  52. array(
  53. 'nid' => $this->node_user_commented->nid,
  54. ),
  55. );
  56. $this->column_map = array('nid' => 'nid');
  57. debug($view->result);
  58. $this->assertIdenticalResultset($view, $resultset, $this->column_map);
  59. }
  60. function view_comment_user_uid() {
  61. $view = new view;
  62. $view->name = 'test_comment_user_uid';
  63. $view->description = '';
  64. $view->tag = 'default';
  65. $view->base_table = 'node';
  66. $view->human_name = 'test_comment_user_uid';
  67. $view->core = 7;
  68. $view->api_version = '3.0';
  69. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  70. /* Display: Master */
  71. $handler = $view->new_display('default', 'Master', 'default');
  72. $handler->display->display_options['access']['type'] = 'perm';
  73. $handler->display->display_options['cache']['type'] = 'none';
  74. $handler->display->display_options['query']['type'] = 'views_query';
  75. $handler->display->display_options['query']['options']['query_comment'] = FALSE;
  76. $handler->display->display_options['exposed_form']['type'] = 'basic';
  77. $handler->display->display_options['pager']['type'] = 'full';
  78. $handler->display->display_options['style_plugin'] = 'default';
  79. $handler->display->display_options['row_plugin'] = 'node';
  80. /* Field: Content: nid */
  81. $handler->display->display_options['fields']['nid']['id'] = 'nid';
  82. $handler->display->display_options['fields']['nid']['table'] = 'node';
  83. $handler->display->display_options['fields']['nid']['field'] = 'nid';
  84. /* Contextual filter: Content: User posted or commented */
  85. $handler->display->display_options['arguments']['uid_touch']['id'] = 'uid_touch';
  86. $handler->display->display_options['arguments']['uid_touch']['table'] = 'node';
  87. $handler->display->display_options['arguments']['uid_touch']['field'] = 'uid_touch';
  88. $handler->display->display_options['arguments']['uid_touch']['default_argument_type'] = 'fixed';
  89. $handler->display->display_options['arguments']['uid_touch']['default_argument_skip_url'] = 0;
  90. $handler->display->display_options['arguments']['uid_touch']['summary']['number_of_records'] = '0';
  91. $handler->display->display_options['arguments']['uid_touch']['summary']['format'] = 'default_summary';
  92. $handler->display->display_options['arguments']['uid_touch']['summary_options']['items_per_page'] = '25';
  93. return $view;
  94. }
  95. }