userTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /*
  3. * @file
  4. * Tests for user.drush.inc
  5. */
  6. class userCase extends Drush_TestCase {
  7. /*
  8. * Create, edit, block, and cancel users.
  9. */
  10. public function testUser() {
  11. // user-create
  12. $env = 'dev';
  13. $this->setUpDrupal($env, TRUE);
  14. $root = $this->sites[$env]['root'];
  15. $name = "example";
  16. $options = array(
  17. 'root' => $root,
  18. 'uri' => $env,
  19. 'yes' => NULL,
  20. );
  21. $this->drush('user-create', array($name), $options + array('password' => 'password', 'mail' => "example@example.com"));
  22. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  23. $output = $this->getOutput();
  24. $row = str_getcsv($output);
  25. $uid = $row[1];
  26. $this->assertEquals('example@example.com', $row[2]);
  27. $this->assertEquals($name, $row[0]);
  28. $this->assertEquals(1, $row[3], 'Newly created user is Active.');
  29. $this->assertEquals('authenticated user', $row[4], 'Newly created user has one role.');
  30. // user-block
  31. $this->drush('user-block', array($name), $options);
  32. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  33. $output = $this->getOutput();
  34. $row = str_getcsv($output);
  35. $this->assertEquals(0, $row[3], 'User is blocked.');
  36. // user-unblock
  37. $this->drush('user-unblock', array($name), $options);
  38. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  39. $output = $this->getOutput();
  40. $row = str_getcsv($output);
  41. $this->assertEquals(1, $row[3], 'User is unblocked.');
  42. // user-add-role
  43. // first, create the fole since we use testing install profile.
  44. $eval = "user_role_save((object)array('name' => 'administrator'))";
  45. $this->drush('php-eval', array($eval), $options);
  46. $this->drush('user-add-role', array('administrator', $name), $options);
  47. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  48. $output = $this->getOutput();
  49. $row = str_getcsv($output);
  50. $this->assertEquals('authenticated user, administrator', $row[4], 'User has administrator role.');
  51. // user-remove-role
  52. $this->drush('user-remove-role', array('administrator', $name), $options);
  53. $this->drush('user-information', array($name), $options + array('pipe' => NULL));
  54. $output = $this->getOutput();
  55. $row = str_getcsv($output);
  56. $this->assertEquals('authenticated user', $row[4], 'User removed administrator role.');
  57. // user-password
  58. $newpass = 'newpass';
  59. $this->drush('user-password', array($name), $options + array('password' => $newpass));
  60. $eval = "require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');";
  61. $eval .= "\$account = user_load_by_name('example');";
  62. $eval .= "print (string) user_check_password('$newpass', \$account)";
  63. $this->drush('php-eval', array($eval), $options);
  64. $output = $this->getOutput();
  65. $this->assertEquals('1', $output, 'User can login with new password.');
  66. // user-login
  67. $this->drush('user-login', array($name), $options);
  68. $output = $this->getOutput();
  69. $url = parse_url($output);
  70. $this->assertStringStartsWith('/user/reset/' . $uid, $url['path'], 'Login returned a valid reset URL');
  71. // user-cancel
  72. // create content
  73. $eval = $this->create_node_types_php();
  74. $this->drush('php-eval', array($eval), $options);
  75. $eval = "
  76. \$node = (object) array(
  77. 'title' => 'foo',
  78. 'uid' => 2,
  79. 'type' => 'page',
  80. );
  81. node_save(\$node);
  82. ";
  83. $this->drush('php-eval', array($eval), $options);
  84. $this->drush('user-cancel', array($name), $options + array('delete-content' => NULL));
  85. $eval = 'print (string) user_load(2)';
  86. $this->drush('php-eval', array($eval), $options);
  87. $output = $this->getOutput();
  88. $this->assertEmpty($output, 'User was deleted');
  89. $eval = 'print (string) node_load(2)';
  90. $this->drush('php-eval', array($eval), $options);
  91. $output = $this->getOutput();
  92. $this->assertEmpty($output, 'Content was deleted');
  93. }
  94. }