t('versioncontrol_svn pre-commit hook'), 'description' => t('Test the functionality of the SVN pre-commit hook'), 'group' => t('Version Control - SVN Integration'), ); } /** * Test printing of help message when incorrect number arguments is given. */ function testInvalidArgHelp() { $this->initRepo(); $this->initHook('pre-commit'); $result = shell_exec($this->hooks['pre-commit']['svn_file'] .' 2>&1'); $usage_text = t('Usage: php !cli REPO_PATH TX_NAME', array('!cli' => $this->hooks['pre-commit']['dst'])); $this->assertTrue( is_int(strpos($result, $usage_text)), t('Print help text when incorrect number of arguments is given.'), t('Shell Interaction') ); } /** * Test denying unauthorized user from committing to the repository. * * May be overly dependent on the exact strings returned by Subversion. */ function testDenyUnauthorized() { $this->initRepo(); $this->initHook('pre-commit'); $result = $this->wcCheckOut(); $this->assertTrue( is_int(strpos($result, "Checked out revision 0.\n")), t('Check out the initial svn version.'), t('Shell Interaction') ); $path = $this->randomName(); $contents = $this->randomName(); $result = $this->wcAddSampleFile($path, $contents); $this->assertTrue( is_int(strpos($result, "A $path\n")), t('Add test file to the repository.'), t('Shell Interaction') ); // Attempt to commit, but fail because the system user does not have access. $message = $this->randomName(); $result = $this->wcCommit($message); $error_msg = t( "** ERROR: Version Control API cannot determine a repository\n". '** for the !commit-branch-or-tag information given by the VCS backend.', array('!commit-branch-or-tag' => t('commit')) ); $this->assertTrue( is_int(strpos($result, $error_msg)), t('Cannot commit with no existing repository.'), t('Shell Interaction') ); // Add a repository, but don't register an account. $user = $this->drupalCreateUser(array('administer version control systems')); $this->drupalLogin($user); $this->repo['name'] = $this->randomName(); $this->initDrupalRepo(); $result = $this->wcCommit(); $error_msg = t( '** ERROR: !user does not have commit access to this repository.', array('!user' => $this->server_user) ); $this->assertTrue( is_int(strpos($result, $error_msg)), t('Cannot commit to repository without an account on that repository.'), t('pre-commit hook') ); } /** * Test committing by an authorized user. */ function testAuthorizedCommit() { $this->initRepo(); $this->initHook('pre-commit'); $user = $this->drupalCreateUser(array('administer version control systems')); $this->drupalLogin($user); $this->repo['name'] = $this->randomName(); $repo = $this->initDrupalRepo(); $result = $this->wcCheckOut(); $path = $this->randomName(); $content = $this->randomName(); $result = $this->wcAddSampleFile($path, $content); $this->initSvnAccount($user->uid, $this->server_user); // TODO: should be able to commit with only 'use version control systems' $message = $this->randomName(); $result = $this->wcCommit($message); $this->assertTrue( preg_match('/Committed revision [0-9]+\./', $result), t('Successfully committed after authorization.'), t('pre-commit hook') ); } }