Index: trunk/extensions/FlaggedRevs/maintenance/tests/FlaggedRevsTestSuite.php |
— | — | @@ -0,0 +1,20 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once 'PHPUnit\Framework\TestSuite.php'; |
| 5 | + |
| 6 | +class FlaggedRevsTestSuite extends PHPUnit_Framework_TestSuite { |
| 7 | + /** |
| 8 | + * Constructs the test suite handler. |
| 9 | + */ |
| 10 | + public function __construct() { |
| 11 | + $this->setName( 'FlaggedRevs' ); |
| 12 | + $this->addTestSuite( 'FRInclusionManagerTest' ); |
| 13 | + } |
| 14 | + |
| 15 | + /** |
| 16 | + * Creates the suite. |
| 17 | + */ |
| 18 | + public static function suite() { |
| 19 | + return new self(); |
| 20 | + } |
| 21 | +} |
Property changes on: trunk/extensions/FlaggedRevs/maintenance/tests/FlaggedRevsTestSuite.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 22 | + native |
Index: trunk/extensions/FlaggedRevs/maintenance/tests/FRInclusionManagerTest.php |
— | — | @@ -0,0 +1,163 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once 'PHPUnit\Framework\TestCase.php'; |
| 5 | + |
| 6 | +define( 'MEDIAWIKI', 1 ); // hack |
| 7 | +if ( getenv( 'MW_INSTALL_PATH' ) ) { |
| 8 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
| 9 | +} else { |
| 10 | + $IP = dirname(__FILE__).'/../../../..'; |
| 11 | +} |
| 12 | +require_once "$IP/includes/defines.php"; // constants (NS_FILE ect...) |
| 13 | +require_once dirname(__FILE__).'/../../FRInclusionManager.php'; |
| 14 | + |
| 15 | +##### Fake classes for dependencies #### |
| 16 | +class Title { |
| 17 | + protected $ns; |
| 18 | + protected $dbKey; |
| 19 | + public static function makeTitleSafe( $ns, $dbKey ) { |
| 20 | + $t = new self(); |
| 21 | + $t->ns = (int)$ns; |
| 22 | + $t->dbKey = (string)$dbKey; |
| 23 | + return $t; |
| 24 | + } |
| 25 | + public function getNamespace() { |
| 26 | + return $this->ns; |
| 27 | + } |
| 28 | + public function getDBKey() { |
| 29 | + return $this->dbKey; |
| 30 | + } |
| 31 | +} |
| 32 | +class FlaggedRevision { |
| 33 | + public static function newFromStable() { |
| 34 | + return null; // not in DB |
| 35 | + } |
| 36 | +} |
| 37 | +class MWException extends Exception { } // just in case |
| 38 | +##### End fake classes ##### |
| 39 | + |
| 40 | +class FRInclusionManagerTest extends PHPUnit_Framework_TestCase { |
| 41 | + /* starting input */ |
| 42 | + protected static $inputTmps = array( |
| 43 | + 10 => array('XX' => '1242', 'YY' => '0'), |
| 44 | + 4 => array('cite' => '30', 'moo' => 0), |
| 45 | + 0 => array('ZZ' => 464) |
| 46 | + ); |
| 47 | + protected static $inputFiles = array( |
| 48 | + 'fXX' => array('ts' => '20100405192110', 'sha1' => 'abc1'), |
| 49 | + 'fYY' => array('ts' => '20000403101300', 'sha1' => 'ffc2'), |
| 50 | + 'fZZ' => array('ts' => '0', 'sha1' => ''), |
| 51 | + 'fle' => array('ts' => 0, 'sha1' => '') |
| 52 | + ); |
| 53 | + /* output to test against (test# => test) */ |
| 54 | + protected static $rOutputTmps = array( |
| 55 | + 0 => array( 10, 'XX', 1242 ), |
| 56 | + 1 => array( 10, 'YY', 0 ), |
| 57 | + 2 => array( 4, 'cite', 30 ), |
| 58 | + 3 => array( 4, 'moo', 0 ), |
| 59 | + 4 => array( 0, 'ZZ', 464 ), |
| 60 | + 5 => array( 0, 'notexists', null ) |
| 61 | + ); |
| 62 | + protected static $rOutputFiles = array( |
| 63 | + 0 => array( 'fXX', '20100405192110', 'abc1'), |
| 64 | + 1 => array( 'fYY', '20000403101300', 'ffc2'), |
| 65 | + 2 => array( 'fZZ', '0', ''), |
| 66 | + 3 => array( 'fle', '0', ''), |
| 67 | + 4 => array( 'notgiven', null, null), |
| 68 | + ); |
| 69 | + protected static $sOutputTmps = array( |
| 70 | + 0 => array( 10, 'XX', 1242 ), |
| 71 | + 1 => array( 10, 'YY', 0 ), |
| 72 | + 2 => array( 4, 'cite', 30 ), |
| 73 | + 3 => array( 4, 'moo', 0 ), |
| 74 | + 4 => array( 0, 'ZZ', 464 ), |
| 75 | + 5 => array( 0, 'notexists', 0 ) |
| 76 | + ); |
| 77 | + protected static $sOutputFiles = array( |
| 78 | + 0 => array( 'fXX', '20100405192110', 'abc1'), |
| 79 | + 1 => array( 'fYY', '20000403101300', 'ffc2'), |
| 80 | + 2 => array( 'fZZ', '0', ''), |
| 81 | + 3 => array( 'fle', '0', ''), |
| 82 | + 4 => array( 'notgiven', '0', ''), |
| 83 | + ); |
| 84 | + |
| 85 | + /** |
| 86 | + * Prepares the environment before running a test. |
| 87 | + */ |
| 88 | + protected function setUp() { |
| 89 | + parent::setUp(); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Cleans up the environment after running a test. |
| 94 | + */ |
| 95 | + protected function tearDown() { |
| 96 | + parent::tearDown(); |
| 97 | + FRInclusionManager::singleton()->clear(); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Constructs the test case. |
| 102 | + */ |
| 103 | + public function __construct() {} |
| 104 | + |
| 105 | + public function testManagerInitial() { |
| 106 | + $im = FRInclusionManager::singleton(); |
| 107 | + $this->assertEquals( false, $im->parserOutputIsStabilized(), "Starts off empty" ); |
| 108 | + } |
| 109 | + |
| 110 | + public function testManagerClear() { |
| 111 | + $im = FRInclusionManager::singleton(); |
| 112 | + $im->setReviewedVersions( self::$inputTmps, self::$inputFiles ); |
| 113 | + $im->clear(); |
| 114 | + $this->assertEquals( false, $im->parserOutputIsStabilized(), "Empty on clear()" ); |
| 115 | + } |
| 116 | + |
| 117 | + public function testReviewedTemplateVersions() { |
| 118 | + $im = FRInclusionManager::singleton(); |
| 119 | + $im->setReviewedVersions( self::$inputTmps, self::$inputFiles ); |
| 120 | + foreach ( self::$rOutputTmps as $x => $triple ) { |
| 121 | + list($ns,$dbKey,$expId) = $triple; |
| 122 | + $title = Title::makeTitleSafe( $ns, $dbKey ); |
| 123 | + $actual = $im->getReviewedTemplateVersion( $title ); |
| 124 | + $this->assertEquals( $expId, $actual, "Rev ID test case $x" ); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + public function testReviewedFileVersions() { |
| 129 | + $im = FRInclusionManager::singleton(); |
| 130 | + $im->setReviewedVersions( self::$inputTmps, self::$inputFiles ); |
| 131 | + foreach ( self::$rOutputFiles as $x => $triple ) { |
| 132 | + list($dbKey,$expTS,$expSha1) = $triple; |
| 133 | + $title = Title::makeTitleSafe( NS_FILE, $dbKey ); |
| 134 | + list($actualTS,$actualSha1) = $im->getReviewedFileVersion( $title ); |
| 135 | + $this->assertEquals( $expTS, $actualTS, "Timestamp test case $x" ); |
| 136 | + $this->assertEquals( $expSha1, $actualSha1, "Sha1 test case $x" ); |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + public function testStableTemplateVersions() { |
| 141 | + $im = FRInclusionManager::singleton(); |
| 142 | + $im->setReviewedVersions( array(), array() ); |
| 143 | + $im->setStableVersionCache( self::$inputTmps, self::$inputFiles ); |
| 144 | + foreach ( self::$sOutputTmps as $x => $triple ) { |
| 145 | + list($ns,$dbKey,$expId) = $triple; |
| 146 | + $title = Title::makeTitleSafe( $ns, $dbKey ); |
| 147 | + $actual = $im->getStableTemplateVersion( $title ); |
| 148 | + $this->assertEquals( $expId, $actual, "Rev ID test case $x" ); |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + public function testStableFileVersions() { |
| 153 | + $im = FRInclusionManager::singleton(); |
| 154 | + $im->setReviewedVersions( array(), array() ); |
| 155 | + $im->setStableVersionCache( self::$inputTmps, self::$inputFiles ); |
| 156 | + foreach ( self::$sOutputFiles as $x => $triple ) { |
| 157 | + list($dbKey,$expTS,$expSha1) = $triple; |
| 158 | + $title = Title::makeTitleSafe( NS_FILE, $dbKey ); |
| 159 | + list($actualTS,$actualSha1) = $im->getStableFileVersion( $title ); |
| 160 | + $this->assertEquals( $expTS, $actualTS, "Timestamp test case $x" ); |
| 161 | + $this->assertEquals( $expSha1, $actualSha1, "Sha1 test case $x" ); |
| 162 | + } |
| 163 | + } |
| 164 | +} |
Property changes on: trunk/extensions/FlaggedRevs/maintenance/tests/FRInclusionManagerTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 165 | + native |