Add unit test for base project class
[gitphp.git] / test / git / project / ProjectTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
 * Project test class
 *
 * @author Christopher Han <xiphux@gmail.com>
 * @copyright Copyright (c) 2012 Christopher Han
 * @package GitPHP
 * @subpackage GitPHP\Test\Project
 */
class GitPHP_ProjectTest extends PHPUnit_Framework_TestCase
{
        public function testInvalidDirectory()
        {
                $this->setExpectedException('GitPHP_InvalidDirectoryException');
 
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'nonexistentproject.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
        }
 
        public function testInvalidRepo()
        {
                $this->setExpectedException('GitPHP_InvalidGitRepositoryException');
 
                $project = new GitPHP_Project(GITPHP_TEST_RESOURCES, 'testdir', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
        }
 
        public function testDirectoryTraversal()
        {
                $this->setExpectedException('GitPHP_DirectoryTraversalException');
 
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, '../externalrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
        }
 
        public function testSlug()
        {
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'category/subrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
 
                $this->assertEquals('category-subrepo', $project->GetSlug());
        }
 
        public function testPath()
        {
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
 
                $this->assertEquals(GITPHP_TEST_PROJECTROOT . '/testrepo.git', $project->GetPath());
        }
 
        public function testDescription()
        {
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
 
                $this->assertEquals('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempus commodo libero, ut molestie est molestie vel. Proin molestie sodales elit bibendum aliquam. Vestibulum venenatis purus convallis tortor sodales vel scelerisque justo bibendum. Pellentesque egestas, sapien eu pulvinar suscipit, erat nisi mollis sapien, a lacinia urna lectus nec lectus. Fusce ornare diam a quam faucibus auctor aliquet nunc tincidunt. Sed massa tellus, feugiat eu iaculis id, blandit eget nisi. In suscipit commodo erat, et blandit nisl lacinia non. Sed quis tortor nisl. Phasellus egestas sapien nec elit tempor a tempor lectus tincidunt.', $project->GetDescription());
                $this->assertEquals('Lorem ipsum dolor si…', $project->GetDescription(20));
        }
 
        public function testDaemonEnabled()
        {
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
                $this->assertFalse($project->GetDaemonEnabled());
 
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepoexported.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
                $this->assertTrue($project->GetDaemonEnabled());
        }
 
        public function testHead()
        {
                $strategymock = $this->getMock('GitPHP_ProjectLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('LoadHead')->with($this->isInstanceOf('GitPHP_Project'))->will($this->returnValue('refs/heads/master'));
 
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $strategymock);
                $this->assertEquals('refs/heads/master', $project->GetHeadReference());
        }
 
        public function testEpoch()
        {
                $strategymock = $this->getMock('GitPHP_ProjectLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('LoadEpoch')->with($this->isInstanceOf('GitPHP_Project'))->will($this->returnValue('12345678'));
 
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $strategymock);
                $this->assertEquals('12345678', $project->GetEpoch());
        }
 
        public function testAbbreviateHash()
        {
                $strategymock = $this->getMock('GitPHP_ProjectLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('AbbreviateHash')->with($this->isInstanceOf('GitPHP_Project'), $this->equalTo('longhash'))->will($this->returnValue('shorthash'));
 
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $strategymock);
                $this->assertEquals('shorthash', $project->AbbreviateHash('longhash'));
        }
 
        public function testExpandHash()
        {
                $strategymock = $this->getMock('GitPHP_ProjectLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('ExpandHash')->with($this->isInstanceOf('GitPHP_Project'), $this->equalTo('shorthash'))->will($this->returnValue('longhash'));
 
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $strategymock);
                $this->assertEquals('longhash', $project->ExpandHash('shorthash'));
        }
 
        public function testCompareProject()
        {
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
                $project2 = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepoexported.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
 
                $this->assertEquals(0, GitPHP_Project::CompareProject($project, $project));
                $this->assertLessThan(0, GitPHP_Project::CompareProject($project, $project2));
                $this->assertGreaterThan(0, GitPHP_Project::CompareProject($project2, $project));
 
                $project->SetCategory('b');
                $this->assertEquals(0, GitPHP_Project::CompareProject($project, $project));
                $this->assertGreaterThan(0, GitPHP_Project::CompareProject($project, $project2));
                $this->assertLessThan(0, GitPHP_Project::CompareProject($project2, $project));
 
                $project2->SetCategory('a');
                $this->assertEquals(0, GitPHP_Project::CompareProject($project, $project));
                $this->assertGreaterThan(0, GitPHP_Project::CompareProject($project, $project2));
                $this->assertLessThan(0, GitPHP_Project::CompareProject($project2, $project));
        }
 
        public function testCompareDescription()
        {
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepoexported.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
                $project->SetDescription('A description');
                $project2 = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
                $project->SetDescription('B description');
 
                $this->assertEquals(0, GitPHP_Project::CompareDescription($project, $project));
                $this->assertLessThan(0, GitPHP_Project::CompareDescription($project, $project2));
                $this->assertGreaterThan(0, GitPHP_Project::CompareDescription($project2, $project));
 
                $project->SetCategory('b');
                $this->assertEquals(0, GitPHP_Project::CompareDescription($project, $project));
                $this->assertGreaterThan(0, GitPHP_Project::CompareDescription($project, $project2));
                $this->assertLessThan(0, GitPHP_Project::CompareDescription($project2, $project));
 
                $project2->SetCategory('a');
                $this->assertEquals(0, GitPHP_Project::CompareDescription($project, $project));
                $this->assertGreaterThan(0, GitPHP_Project::CompareDescription($project, $project2));
                $this->assertLessThan(0, GitPHP_Project::CompareDescription($project2, $project));
        }
 
        public function testCompareOwner()
        {
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepoexported.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
                $project->SetOwner('A owner');
                $project2 = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $this->getMock('GitPHP_ProjectLoadStrategy_Interface'));
                $project->SetOwner('B owner');
 
                $this->assertEquals(0, GitPHP_Project::CompareOwner($project, $project));
                $this->assertLessThan(0, GitPHP_Project::CompareOwner($project, $project2));
                $this->assertGreaterThan(0, GitPHP_Project::CompareOwner($project2, $project));
 
                $project->SetCategory('b');
                $this->assertEquals(0, GitPHP_Project::CompareOwner($project, $project));
                $this->assertGreaterThan(0, GitPHP_Project::CompareOwner($project, $project2));
                $this->assertLessThan(0, GitPHP_Project::CompareOwner($project2, $project));
 
                $project2->SetCategory('a');
                $this->assertEquals(0, GitPHP_Project::CompareOwner($project, $project));
                $this->assertGreaterThan(0, GitPHP_Project::CompareOwner($project, $project2));
                $this->assertLessThan(0, GitPHP_Project::CompareOwner($project2, $project));
        }
 
        public function testCompareAge()
        {
                $strategymock = $this->getMock('GitPHP_ProjectLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('LoadEpoch')->with($this->isInstanceOf('GitPHP_Project'))->will($this->returnValue('2'));
                $project = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepoexported.git', $strategymock);
 
                $strategymock2 = $this->getMock('GitPHP_ProjectLoadStrategy_Interface');
                $strategymock2->expects($this->once())->method('LoadEpoch')->with($this->isInstanceOf('GitPHP_Project'))->will($this->returnValue('1'));
                $project2 = new GitPHP_Project(GITPHP_TEST_PROJECTROOT, 'testrepo.git', $strategymock2);
 
                $this->assertEquals(0, GitPHP_Project::CompareAge($project, $project));
                $this->assertLessThan(0, GitPHP_Project::CompareAge($project, $project2));
                $this->assertGreaterThan(0, GitPHP_Project::CompareAge($project2, $project));
 
                $project->SetCategory('b');
                $this->assertEquals(0, GitPHP_Project::CompareAge($project, $project));
                $this->assertGreaterThan(0, GitPHP_Project::CompareAge($project, $project2));
                $this->assertLessThan(0, GitPHP_Project::CompareAge($project2, $project));
 
                $project2->SetCategory('a');
                $this->assertEquals(0, GitPHP_Project::CompareAge($project, $project));
                $this->assertGreaterThan(0, GitPHP_Project::CompareAge($project, $project2));
                $this->assertLessThan(0, GitPHP_Project::CompareAge($project2, $project));
        }
 
}
 
comments