Esempio n. 1
0
 /**
  * Assert that commands in disabled modules are detected.
  */
 public function testDisabledModule()
 {
     $sites = $this->setUpDrupal(1, TRUE);
     $uri = key($sites);
     $root = $this->webroot();
     $options = array('root' => $root, 'uri' => $uri);
     $this->drush('pm-download', array('devel'), $options);
     $options += array('backend' => NULL);
     $this->drush('devel-download', array(), $options, NULL, NULL, self::EXIT_ERROR);
     $parsed = parse_backend_output($this->getOutput());
     $this->assertArrayHasKey("DRUSH_COMMAND_DEPENDENCY_ERROR", $parsed['error_log']);
 }
Esempio n. 2
0
 public function testBatch()
 {
     $sites = $this->setUpDrupal(1, TRUE);
     $options = array('root' => $this->webroot(), 'uri' => key($sites), 'yes' => NULL, 'include' => dirname(__FILE__));
     $this->drush('unit-batch', array(), $options);
     // Collect log messages that begin with "!!!" (@see: _drush_unit_batch_operation())
     $parsed = parse_backend_output($this->getOutput());
     $special_log_msgs = '';
     foreach ($parsed['log'] as $key => $log) {
         if (substr($log['message'], 0, 3) == '!!!') {
             $special_log_msgs .= $log['message'];
         }
     }
     $this->assertEquals("!!! ArrayObject does its job.", $special_log_msgs, 'Batch messages were logged');
 }
Esempio n. 3
0
 /**
  * Covers the following target responsibilities.
  *   - Insures that backend invoke can properly re-assemble packets
  *     that are split across process-read-size boundaries.
  *
  * This test works by repeating testBackendMethodGet(), while setting
  * '#process-read-size' to a very small value, insuring that packets
  * will be split.
  */
 function testBackendReassembleSplitPackets()
 {
     $options = array('backend' => NULL, 'include' => dirname(__FILE__));
     $read_sizes_to_test = array(4096, 128, 16);
     foreach ($read_sizes_to_test as $read_size) {
         $log_message = "";
         for ($i = 1; $i <= 16; $i++) {
             $log_message .= "X";
             $php = "\$values = drush_invoke_process('@none', 'unit-return-options', array('value'), array('log-message' => '{$log_message}', 'x' => 'y{$read_size}', 'data' => array('a' => 1, 'b' => 2)), array('method' => 'GET', '#process-read-size' => {$read_size})); return array_key_exists('object', \$values) ? \$values['object'] : 'no result';";
             $this->drush('php-eval', array($php), $options);
             $parsed = parse_backend_output($this->getOutput());
             // assert that $parsed has 'x' but not 'data'
             $all_warnings = array();
             foreach ($parsed['log'] as $log) {
                 if ($log['type'] == 'warning') {
                     $all_warnings[] = $log['message'];
                 }
             }
             $this->assertEquals("{$log_message},done", implode(',', $all_warnings), 'Log reconstruction with read_size ' . $read_size);
             $this->assertEquals("array (\n  'x' => 'y{$read_size}',\n)", var_export($parsed['object'], TRUE));
         }
     }
 }
 /**
  * Covers the following target responsibilities.
  *   - Insures that complex arrays can be passed through when using --backend mode's method POST
  *   - Insures that arrays can be returned as the function result of
  *     backend invoke.
  */
 function testBackendMethodPost()
 {
     $options = array('backend' => NULL, 'include' => dirname(__FILE__));
     $php = "\$values = drush_invoke_process('@none', 'unit-return-options', array('value'), array('x' => 'y', 'data' => array('a' => 1, 'b' => 2)), array('method' => 'POST')); return array_key_exists('object', \$values) ? \$values['object'] : 'no result';";
     $this->drush('php-eval', array($php), $options);
     $parsed = parse_backend_output($this->getOutput());
     // assert that $parsed has 'x' and 'data'
     $this->assertEquals("array (\n  'x' => 'y',\n  'data' => \n  array (\n    'a' => 1,\n    'b' => 2,\n  ),\n)", var_export($parsed['object'], TRUE));
 }
Esempio n. 5
0
  /**
   * Create, edit, block, and cancel users.
   */
  public function testUser() {
    // user-create
    $sites = $this->setUpDrupal(1, TRUE);
    $root = $this->webroot();
    $name = "example";
    $options = array(
      'root' => $root,
      'uri' => key($sites),
      'yes' => NULL,
    );
    $authenticated = 'authenticated';
    if (UNISH_DRUPAL_MAJOR_VERSION < 8) {
      $authenticated .= ' user';
    }
    $this->drush('user-create', array($name), $options + array('password' => 'password', 'mail' => "*****@*****.**"));
    $this->drush('user-information', array($name), $options + array('format' => 'json'));
    $output = $this->getOutputFromJSON('2');
    $this->assertEquals('*****@*****.**', $output->mail);
    $this->assertEquals($name, $output->name);
    $this->assertEquals(1, $output->status, 'Newly created user is Active.');
    $expected = array($authenticated);
    $this->assertEquals($expected, array_values((array)$output->roles), 'Newly created user has one role.');

    // user-block
    $this->drush('user-block', array($name), $options);
    $this->drush('user-information', array($name), $options + array('format' => 'json'));
    $output = $this->getOutputFromJSON('2');
    $this->assertEquals(0, $output->status, 'User is blocked.');

    // user-unblock
    $this->drush('user-unblock', array($name), $options);
    $this->drush('user-information', array($name), $options + array('format' => 'json'));
    $output = $this->getOutputFromJSON('2');
    $this->assertEquals(1, $output->status, 'User is unblocked.');

    // user-add-role
    // first, create the fole since we use testing install profile.
    $this->drush('role-create', array('test role'), $options);
    $this->drush('user-add-role', array('test role', $name), $options);
    $this->drush('user-information', array($name), $options + array('format' => 'json'));
    $output = $this->getOutputFromJSON('2');
    $expected = array($authenticated, 'test role');
    $this->assertEquals($expected, array_values((array)$output->roles), 'User has test role.');

    // user-remove-role
    $this->drush('user-remove-role', array('test role', $name), $options);
    $this->drush('user-information', array($name), $options + array('format' => 'json'));
    $output = $this->getOutputFromJSON('2');
    $expected = array($authenticated);
    $this->assertEquals($expected, array_values((array)$output->roles), 'User removed test role.');

    // user-password
    $newpass = '******';
    $this->drush('user-password', array($name), $options + array('password' => $newpass));
    // There is no user_check_password in D6
    if (UNISH_DRUPAL_MAJOR_VERSION >= 7) {
      $eval = "require_once DRUSH_DRUPAL_CORE . '/' . variable_get('password_inc', 'includes/password.inc');";
      $eval .= "\$account = user_load_by_name('example');";
      $eval .= "print (string) user_check_password('$newpass', \$account)";
      $this->drush('php-eval', array($eval), $options);
      $output = $this->getOutput();
      $this->assertEquals('1', $output, 'User can login with new password.');
    }

    // user-login
    // Check if user-login on non-bootstrapped environment returns error.
    $this->drush('user-login', array(), array(), NULL, NULL, self::EXIT_ERROR);

    // Check user-login
    $user_login_options = $options + array('simulate' => TRUE, 'browser' => 'unish');
    // Collect full logs so we can check browser.
    $this->drush('user-login', array(), $user_login_options + array('backend' => NULL));
    $parsed = parse_backend_output($this->getOutput());
    $url = parse_url($parsed['output']);
    $this->assertContains('/user/reset/1', $url['path'], 'Login returned a reset URL for uid 1 by default');
    $browser = FALSE;
    foreach ($parsed['log'] as $key => $log) {
      if (strpos($log['message'], 'Opening browser unish at http://') === 0) {
        $browser = TRUE;
      }
    }
    $this->assertEquals($browser, TRUE, 'Correct browser opened at correct URL');
    // Check specific user and path argument.
    $uid = 2;
    $this->drush('user-login', array($name, 'node/add'), $user_login_options);
    $output = $this->getOutput();
    $url = parse_url($output);
    // user_pass_reset_url encodes the URL in D6, but not in D7 or D8
    $query = $url['query'];
    if (UNISH_DRUPAL_MAJOR_VERSION < 7) {
      $query = urldecode($query);
    }
    $this->assertContains('/user/reset/' . $uid, $url['path'], 'Login with user argument returned a valid reset URL');
    $this->assertEquals('destination=node/add', $query, 'Login included destination path in URL');
    // Check path used as only argument when using uid option.
    $this->drush('user-login', array('node/add'), $user_login_options + array('uid' => $uid));
    $output = $this->getOutput();
    $url = parse_url($output);
    $this->assertContains('/user/reset/' . $uid, $url['path'], 'Login with uid option returned a valid reset URL');
    $query = $url['query'];
    if (UNISH_DRUPAL_MAJOR_VERSION < 7) {
      $query = urldecode($query);
    }
    $this->assertEquals('destination=node/add', $query, 'Login included destination path in URL');

    // user-cancel
    // create content
    if (UNISH_DRUPAL_MAJOR_VERSION >= 7) {
      // create_node_types script does not work for D6
      $this->drush('php-script', array('create_node_types'), $options + array('script-path' => dirname(__FILE__) . '/resources'));
      $this->drush('php-eval', array($eval), $options);
      $eval = "\$node = (object) array('title' => 'foo', 'uid' => 2, 'type' => 'page',);";
      if (UNISH_DRUPAL_MAJOR_VERSION >= 8) {
        $eval .= " \$node = node_submit(entity_create('node', \$node));";
      }
      $eval .= " node_save(\$node);";
      $this->drush('php-eval', array($eval), $options);
      $this->drush('user-cancel', array($name), $options + array('delete-content' => NULL));
      $eval = 'print (string) user_load(2)';
      $this->drush('php-eval', array($eval), $options);
      $output = $this->getOutput();
      $this->assertEmpty($output, 'User was deleted');
      $eval = 'print (string) node_load(2)';
      $this->drush('php-eval', array($eval), $options);
      $output = $this->getOutput();
      $this->assertEmpty($output, 'Content was deleted');
    }
  }
Esempio n. 6
0
 /**
  * Covers the following target responsibilities.
  *   - Insures that backend_set_result is returned in --backend mode
  *   - Insures that the result code for the function does not overwrite
  *     the explicitly-set value
  */
 function testBackendSetResult()
 {
     $php = "drush_backend_set_result('foo'); return 'bar'";
     $this->drush('php-eval', array($php), array('backend' => NULL));
     $parsed = parse_backend_output($this->getOutput());
     // assert that $parsed has 'foo' and not 'bar'
     $this->assertEquals("'foo'", var_export($parsed['object'], TRUE));
 }
Esempio n. 7
0
 public function testUser()
 {
     // user-create
     $sites = $this->setUpDrupal(1, TRUE);
     $root = $this->webroot();
     $name = "example";
     $options = array('root' => $root, 'uri' => key($sites), 'yes' => NULL);
     $this->drush('user-create', array($name), $options + array('password' => 'password', 'mail' => "*****@*****.**"));
     $this->drush('user-information', array($name), $options + array('pipe' => NULL));
     $output = $this->getOutput();
     $row = str_getcsv($output);
     $uid = $row[1];
     $this->assertEquals('*****@*****.**', $row[2]);
     $this->assertEquals($name, $row[0]);
     $this->assertEquals(1, $row[3], 'Newly created user is Active.');
     $this->assertEquals('authenticated user', $row[4], 'Newly created user has one role.');
     // user-block
     $this->drush('user-block', array($name), $options);
     $this->drush('user-information', array($name), $options + array('pipe' => NULL));
     $output = $this->getOutput();
     $row = str_getcsv($output);
     $this->assertEquals(0, $row[3], 'User is blocked.');
     // user-unblock
     $this->drush('user-unblock', array($name), $options);
     $this->drush('user-information', array($name), $options + array('pipe' => NULL));
     $output = $this->getOutput();
     $row = str_getcsv($output);
     $this->assertEquals(1, $row[3], 'User is unblocked.');
     // user-add-role
     // first, create the fole since we use testing install profile.
     $eval = "user_role_save((object)array('name' => 'administrator'))";
     $this->drush('php-eval', array($eval), $options);
     $this->drush('user-add-role', array('administrator', $name), $options);
     $this->drush('user-information', array($name), $options + array('pipe' => NULL));
     $output = $this->getOutput();
     $row = str_getcsv($output);
     $this->assertEquals('authenticated user,administrator', $row[4], 'User has administrator role.');
     // user-remove-role
     $this->drush('user-remove-role', array('administrator', $name), $options);
     $this->drush('user-information', array($name), $options + array('pipe' => NULL));
     $output = $this->getOutput();
     $row = str_getcsv($output);
     $this->assertEquals('authenticated user', $row[4], 'User removed administrator role.');
     // user-password
     $newpass = '******';
     $this->drush('user-password', array($name), $options + array('password' => $newpass));
     $eval = "require_once DRUSH_DRUPAL_CORE . '/' . variable_get('password_inc', 'includes/password.inc');";
     $eval .= "\$account = user_load_by_name('example');";
     $eval .= "print (string) user_check_password('{$newpass}', \$account)";
     $this->drush('php-eval', array($eval), $options);
     $output = $this->getOutput();
     $this->assertEquals('1', $output, 'User can login with new password.');
     // user-login
     $user_login_options = $options + array('simulate' => TRUE, 'browser' => 'unish');
     // Collect full logs so we can check browser.
     $this->drush('user-login', array(), $user_login_options + array('backend' => NULL));
     $parsed = parse_backend_output($this->getOutput());
     $url = parse_url($parsed['output']);
     $this->assertStringStartsWith('/user/reset/1', $url['path'], 'Login returned a reset URL for uid 1 by default');
     $browser = FALSE;
     foreach ($parsed['log'] as $key => $log) {
         if (strpos($log['message'], 'Opening browser unish at http://dev/user/reset/1') === 0) {
             $browser = TRUE;
         }
     }
     $this->assertEquals($browser, TRUE, 'Correct browser opened at correct URL');
     // Check specific user and path argument.
     $this->drush('user-login', array($name, 'node/add'), $user_login_options);
     $output = $this->getOutput();
     $url = parse_url($output);
     $this->assertStringStartsWith('/user/reset/' . $uid, $url['path'], 'Login with user argument returned a valid reset URL');
     $this->assertEquals('destination=node/add', $url['query'], 'Login included destination path in URL');
     // Check path used as only argument when using uid option.
     $this->drush('user-login', array('node/add'), $user_login_options + array('uid' => $uid));
     $output = $this->getOutput();
     $url = parse_url($output);
     $this->assertStringStartsWith('/user/reset/' . $uid, $url['path'], 'Login with uid option returned a valid reset URL');
     $this->assertEquals('destination=node/add', $url['query'], 'Login included destination path in URL');
     // user-cancel
     // create content
     $this->drush('php-script', array('create_node_types'), $options + array('script-path' => dirname(__FILE__) . '/resources'));
     $this->drush('php-eval', array($eval), $options);
     $eval = "\$node = (object) array('title' => 'foo', 'uid' => 2, 'type' => 'page',); node_save(\$node);";
     $this->drush('php-eval', array($eval), $options);
     $this->drush('user-cancel', array($name), $options + array('delete-content' => NULL));
     $eval = 'print (string) user_load(2)';
     $this->drush('php-eval', array($eval), $options);
     $output = $this->getOutput();
     $this->assertEmpty($output, 'User was deleted');
     $eval = 'print (string) node_load(2)';
     $this->drush('php-eval', array($eval), $options);
     $output = $this->getOutput();
     $this->assertEmpty($output, 'Content was deleted');
 }