wiki.techinc.nl/tests/phpunit/includes/GitInfoTest.php
Bryan Davis b6d18ab9f7 Fix GitInfo cache file path computation and storage location
Depending on the configuration used in LocalSettings.php, $IP can be
changed between the time that configuration is loaded and the wiki
runtime by logic in WebStart.php. Attempt to mitigate the effects of
such changes on the cache file name computation by canonicalizing both
$IP and the path using PHP's realpath() function.

Related but distinct is the possible need to configure the canonical
location for finding cache files on disk separately from
$wgCacheDirectory. This change introduces a new configuration variable
named $wgGitInfoCacheDirectory that can be set to a path that diverges
from the default location of $wgCacheDirectory/gitinfo. This will be
useful in the WMF cluster where $wgCacheDirectory points to a directory
that is not managed by the deployment system.

Finally add wfDebugLog logging to make tracking down issues such as
miscomputed cache paths easier.

Bug: 53972
Change-Id: Iceb9e1ce8d3b4bb08f89fa6ec5d5e7392aaafd46
2014-07-08 16:36:10 +00:00

42 lines
1.4 KiB
PHP

<?php
/**
* @covers GitInfo
*/
class GitInfoTest extends MediaWikiTestCase {
protected function setUp() {
parent::setUp();
$this->setMwGlobals( 'wgGitInfoCacheDirectory', __DIR__ . '/../data/gitinfo' );
}
public function testValidJsonData() {
$dir = $GLOBALS['IP'] . '/testValidJsonData';
$fixture = new GitInfo( $dir );
$this->assertTrue( $fixture->cacheIsComplete() );
$this->assertEquals( 'refs/heads/master', $fixture->getHead() );
$this->assertEquals( '0123456789abcdef0123456789abcdef01234567',
$fixture->getHeadSHA1() );
$this->assertEquals( '1070884800', $fixture->getHeadCommitDate() );
$this->assertEquals( 'master', $fixture->getCurrentBranch() );
$this->assertContains( '0123456789abcdef0123456789abcdef01234567',
$fixture->getHeadViewUrl() );
}
public function testMissingJsonData() {
$dir = $GLOBALS['IP'] . '/testMissingJsonData';
$fixture = new GitInfo( $dir );
$this->assertFalse( $fixture->cacheIsComplete() );
$this->assertEquals( false, $fixture->getHead() );
$this->assertEquals( false, $fixture->getHeadSHA1() );
$this->assertEquals( false, $fixture->getHeadCommitDate() );
$this->assertEquals( false, $fixture->getCurrentBranch() );
$this->assertEquals( false, $fixture->getHeadViewUrl() );
// After calling all the outputs, the cache should be complete
$this->assertTrue( $fixture->cacheIsComplete() );
}
}