RevisionTest: Revision::constructFromRowArray is not a function
[lhc/web/wiklou.git] / tests / phpunit / includes / GitInfoTest.php
1 <?php
2 /**
3 * @covers GitInfo
4 */
5 class GitInfoTest extends MediaWikiTestCase {
6
7 public static function setUpBeforeClass() {
8 mkdir( __DIR__ . '/../data/gitrepo' );
9 mkdir( __DIR__ . '/../data/gitrepo/1' );
10 mkdir( __DIR__ . '/../data/gitrepo/2' );
11 mkdir( __DIR__ . '/../data/gitrepo/3' );
12 mkdir( __DIR__ . '/../data/gitrepo/1/.git' );
13 mkdir( __DIR__ . '/../data/gitrepo/1/.git/refs' );
14 mkdir( __DIR__ . '/../data/gitrepo/1/.git/refs/heads' );
15 file_put_contents( __DIR__ . '/../data/gitrepo/1/.git/HEAD',
16 "ref: refs/heads/master\n" );
17 file_put_contents( __DIR__ . '/../data/gitrepo/1/.git/refs/heads/master',
18 "0123456789012345678901234567890123abcdef\n" );
19 file_put_contents( __DIR__ . '/../data/gitrepo/1/.git/packed-refs',
20 "abcdef6789012345678901234567890123456789 refs/heads/master\n" );
21 file_put_contents( __DIR__ . '/../data/gitrepo/2/.git',
22 "gitdir: ../1/.git\n" );
23 file_put_contents( __DIR__ . '/../data/gitrepo/3/.git',
24 'gitdir: ' . __DIR__ . "/../data/gitrepo/1/.git\n" );
25 }
26
27 public static function tearDownAfterClass() {
28 wfRecursiveRemoveDir( __DIR__ . '/../data/gitrepo' );
29 }
30
31 protected function setUp() {
32 parent::setUp();
33 $this->setMwGlobals( 'wgGitInfoCacheDirectory', __DIR__ . '/../data/gitinfo' );
34 }
35
36 protected function assertValidGitInfo( GitInfo $gitInfo ) {
37 $this->assertTrue( $gitInfo->cacheIsComplete() );
38 $this->assertEquals( 'refs/heads/master', $gitInfo->getHead() );
39 $this->assertEquals( '0123456789abcdef0123456789abcdef01234567',
40 $gitInfo->getHeadSHA1() );
41 $this->assertEquals( '1070884800', $gitInfo->getHeadCommitDate() );
42 $this->assertEquals( 'master', $gitInfo->getCurrentBranch() );
43 $this->assertContains( '0123456789abcdef0123456789abcdef01234567',
44 $gitInfo->getHeadViewUrl() );
45 }
46
47 public function testValidJsonData() {
48 global $IP;
49
50 $this->assertValidGitInfo( new GitInfo( "$IP/testValidJsonData" ) );
51 $this->assertValidGitInfo( new GitInfo( __DIR__ . "/../data/gitinfo/extension" ) );
52 }
53
54 public function testMissingJsonData() {
55 $dir = $GLOBALS['IP'] . '/testMissingJsonData';
56 $fixture = new GitInfo( $dir );
57
58 $this->assertFalse( $fixture->cacheIsComplete() );
59
60 $this->assertEquals( false, $fixture->getHead() );
61 $this->assertEquals( false, $fixture->getHeadSHA1() );
62 $this->assertEquals( false, $fixture->getHeadCommitDate() );
63 $this->assertEquals( false, $fixture->getCurrentBranch() );
64 $this->assertEquals( false, $fixture->getHeadViewUrl() );
65
66 // After calling all the outputs, the cache should be complete
67 $this->assertTrue( $fixture->cacheIsComplete() );
68 }
69
70 public function testReadingHead() {
71 $dir = __DIR__ . '/../data/gitrepo/1';
72 $fixture = new GitInfo( $dir );
73
74 $this->assertEquals( 'refs/heads/master', $fixture->getHead() );
75 $this->assertEquals( '0123456789012345678901234567890123abcdef', $fixture->getHeadSHA1() );
76 }
77
78 public function testIndirection() {
79 $dir = __DIR__ . '/../data/gitrepo/2';
80 $fixture = new GitInfo( $dir );
81
82 $this->assertEquals( 'refs/heads/master', $fixture->getHead() );
83 $this->assertEquals( '0123456789012345678901234567890123abcdef', $fixture->getHeadSHA1() );
84 }
85
86 public function testIndirection2() {
87 $dir = __DIR__ . '/../data/gitrepo/3';
88 $fixture = new GitInfo( $dir );
89
90 $this->assertEquals( 'refs/heads/master', $fixture->getHead() );
91 $this->assertEquals( '0123456789012345678901234567890123abcdef', $fixture->getHeadSHA1() );
92 }
93
94 public function testReadingPackedRefs() {
95 $dir = __DIR__ . '/../data/gitrepo/1';
96 unlink( __DIR__ . '/../data/gitrepo/1/.git/refs/heads/master' );
97 $fixture = new GitInfo( $dir );
98
99 $this->assertEquals( 'refs/heads/master', $fixture->getHead() );
100 $this->assertEquals( 'abcdef6789012345678901234567890123456789', $fixture->getHeadSHA1() );
101 }
102 }