rules_link.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @file
  4. * Views integration.
  5. */
  6. /**
  7. * Test class for Rules link.
  8. */
  9. class RulesLinkTestCase extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Rules link tests',
  13. 'description' => 'Test basic editing and execution of rules links',
  14. 'group' => 'Rules',
  15. );
  16. }
  17. protected $admin;
  18. function setUp() {
  19. parent::setUp('rules_link', 'rules');
  20. $this->admin = $this->drupalCreateUser(array('administer rules links', 'administer permissions', 'administer rules'));
  21. }
  22. /**
  23. * Create a link with the given name and the type.
  24. */
  25. function createLink($name, $type) {
  26. $this->drupalLogin($this->admin);
  27. $this->drupalGet('admin/config/workflow/rules_links/add');
  28. $this->assertText('Add rules link');
  29. $data = array(
  30. 'label' => $name,
  31. 'name' => $name,
  32. 'entity_type' => 'node',
  33. 'bundles[]' => array('article'),
  34. 'text' => $name,
  35. 'link_type' => $type,
  36. 'question' => 'foo?',
  37. 'description' => 'bar!',
  38. 'entity_link' => TRUE,
  39. );
  40. $this->drupalPost('admin/config/workflow/rules_links/add', $data, t('Continue'));
  41. $this->assertText('Your Rules Link has been created along with the required components.');
  42. $this->drupalGet('admin/people/permissions');
  43. $this->assertText("$name: Execute rules link", 'Permission was created.');
  44. //$this->drupalLogout();
  45. // The Simpletest function checkPermissions() saves all permissions into a
  46. // static array, but rules links generates new permissions, when creating
  47. // a link. So we have to reset the static cache, so that the
  48. // checkPermissions function recognizes the new permissions.
  49. drupal_static_reset('checkPermissions');
  50. }
  51. /**
  52. * Test creating a new token link.
  53. */
  54. function testTokenLink() {
  55. $name = 'token_link';
  56. $this->createLink($name, 'token');
  57. $rules_link = rules_link_load($name);
  58. $set = rules_config_load(rules_link_get_rules_set_name($rules_link));
  59. $set->rule(rule()->action('drupal_message', array('message' => 'Rules link executed.')));
  60. $set->save();
  61. $tokenUser = $this->drupalCreateUser(array("access rules link $name", 'administer rules'));
  62. $this->drupalLogin($tokenUser);
  63. $node = $this->drupalCreateNode(array('title' => 'foo', 'type' => 'article'));
  64. $this->drupalGet('node/' . $node->vid);
  65. $this->clickLink($name);
  66. $this->assertText('Rules link executed');//*/
  67. }
  68. /**
  69. * Test creating a new confirmation link.
  70. */
  71. function testConfirmLink() {
  72. $name = 'test_rules_link';
  73. $this->createLink($name, 'confirm');
  74. $rules_link = rules_link_load($name);
  75. $set = rules_config_load(rules_link_get_rules_set_name($rules_link));
  76. $set->rule(rule()->action('drupal_message', array('message' => 'Rules link executed.')));
  77. $set->save();
  78. $user2 = $this->drupalCreateUser(array("access rules link $name"));
  79. $this->drupalLogin($user2);
  80. $node = $this->drupalCreateNode(array('title' => 'foo', 'type' => 'article'));
  81. $this->drupalGet('node/' . $node->vid);
  82. $this->clickLink($name);
  83. $this->drupalPost('test_rules_link/1', array(), t('Confirm'));
  84. $this->assertText('Rules link executed.', 'Confirm form was generated and rules link was executed.');
  85. $this->drupalLogout();
  86. }
  87. }