1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) STMicroelectronics, 2011. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* This file is a part of Codendi. |
6
|
|
|
* |
7
|
|
|
* Codendi is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Codendi is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Codendi; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
require_once 'bootstrap.php'; |
23
|
|
|
|
24
|
|
|
Mock::generatePartial('GitBackend', 'GitBackendTestVersion', array('getDao', 'getDriver', 'getSystemEventManager')); |
25
|
|
|
Mock::generatePartial('GitBackend', 'GitBackend4SetUp', array('getDao', 'getDriver', 'deployPostReceive', 'setRepositoryPermissions', 'changeRepositoryAccess')); |
26
|
|
|
|
27
|
|
|
Mock::generate('GitDriver'); |
28
|
|
|
Mock::generate('GitRepository'); |
29
|
|
|
Mock::generate('GitDao'); |
30
|
|
|
Mock::generate('Project'); |
31
|
|
|
Mock::generate('SystemEventManager'); |
32
|
|
|
|
33
|
|
|
class GitBackendTest extends TuleapTestCase { |
34
|
|
|
|
35
|
|
|
protected $_globals; |
36
|
|
|
|
37
|
|
|
public function setUp() { |
38
|
|
|
$this->_globals = $GLOBALS; |
39
|
|
|
$this->fixturesPath = dirname(__FILE__).'/_fixtures'; |
40
|
|
|
|
41
|
|
|
$git_plugin = stub('GitPlugin')->areFriendlyUrlsActivated()->returns(false); |
42
|
|
|
$this->url_manager = new Git_GitRepositoryUrlManager($git_plugin); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function tearDown() { |
46
|
|
|
$GLOBALS = $this->_globals; |
47
|
|
|
@unlink($this->fixturesPath.'/tmp/hooks/post-receive'); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testAddMailingShowRev() { |
51
|
|
|
$GLOBALS['sys_https_host'] = 'codendi.org'; |
52
|
|
|
|
53
|
|
|
$prj = new MockProject($this); |
54
|
|
|
$prj->setReturnValue('getId', 1750); |
55
|
|
|
|
56
|
|
|
$repo = new GitRepository(); |
57
|
|
|
$repo->setPath('prj/repo.git'); |
58
|
|
|
$repo->setName('repo'); |
59
|
|
|
$repo->setProject($prj); |
60
|
|
|
$repo->setId(290); |
61
|
|
|
|
62
|
|
|
$driver = new MockGitDriver($this); |
63
|
|
|
$driver->expectOnce('setConfig', array('/var/lib/codendi/gitroot/prj/repo.git', 'hooks.showrev', "t=%s; git show --name-status --pretty='format:URL: https://codendi.org/plugins/git/index.php/1750/view/290/?p=repo.git&a=commitdiff&h=%%H%%nAuthor: %%an <%%ae>%%nDate: %%aD%%n%%n%%s%%n%%b' \$t")); |
64
|
|
|
|
65
|
|
|
$backend = new GitBackendTestVersion($this); |
66
|
|
|
$backend->setUp($this->url_manager); |
67
|
|
|
$backend->setGitRootPath(Git_Backend_Interface::GIT_ROOT_PATH); |
68
|
|
|
$backend->setReturnValue('getDriver', $driver); |
69
|
|
|
|
70
|
|
|
$backend->setUpMailingHook($repo); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testArchiveCreatesATarGz() { |
74
|
|
|
$this->GivenThereIsARepositorySetUp(); |
75
|
|
|
|
76
|
|
|
$project = new MockProject(); |
77
|
|
|
$project->setReturnValue('getUnixName', 'zorblub'); |
78
|
|
|
|
79
|
|
|
$repo = new MockGitRepository(); |
80
|
|
|
$repo->setReturnValue('getPath', 'gitolite-admin-ref'); |
81
|
|
|
$repo->setReturnValue('getName', 'gitolite-admin-ref'); |
82
|
|
|
$repo->setReturnValue('getDeletionDate', '2012-01-26'); |
83
|
|
|
$repo->setReturnValue('getProject', $project); |
84
|
|
|
|
85
|
|
|
$backend = new GitBackendTestVersion(); |
86
|
|
|
$backend->setGitRootPath($this->_tmpDir); |
87
|
|
|
$backend->setGitBackupDir($this->backupDir); |
88
|
|
|
$backend->archive($repo); |
89
|
|
|
|
90
|
|
|
$this->ThenCleanTheWorkspace(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function GivenThereIsARepositorySetUp() { |
94
|
|
|
// Copy the reference to save time & create symlink because |
95
|
|
|
// git is very sensitive to path you are using. Just symlinking |
96
|
|
|
// spots bugs |
97
|
|
|
$this->cwd = getcwd(); |
98
|
|
|
$this->_tmpDir = '/tmp'; |
99
|
|
|
$this->_fixDir = dirname(__FILE__).'/_fixtures'; |
100
|
|
|
$this->_glAdmDirRef = $this->_tmpDir.'/gitolite-admin-ref'; |
101
|
|
|
$this->backupDir = $this->_tmpDir.'/backup'; |
102
|
|
|
system('tar -xf '. $this->_fixDir.'/gitolite-admin-ref' .'.tar --directory '.$this->_tmpDir); |
103
|
|
|
mkdir($this->backupDir); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
private function ThenCleanTheWorkspace() { |
107
|
|
|
system('rm -rf '. $this->_glAdmDirRef); |
108
|
|
|
system('rm -rf '. $this->backupDir); |
109
|
|
|
chdir($this->cwd); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
?> |
If you suppress an error, we recommend checking for the error condition explicitly: