MessageIndexTest.php

Go to the documentation of this file.
00001 <?php
00015 class MessageIndexTest extends MediaWikiTestCase {
00016     protected function setUp() {
00017         parent::setUp();
00018         $this->setMwGlobals( array(
00019             'wgTranslateCacheDirectory' => $this->getNewTempDirectory(),
00020             'wgTranslateTranslationServices' => array(),
00021         ) );
00022     }
00023 
00024     protected static function getTestData() {
00025         static $data = null;
00026         if ( $data === null ) {
00027             $data = unserialize( file_get_contents( __DIR__ . '/messageindexdata.ser' ) );
00028         }
00029 
00030         return $data;
00031     }
00032 
00036     public function testMessageIndexImplementation( $mi ) {
00037         $data = self::getTestData();
00039         $mi->store( $data );
00040 
00041         $tests = array_rand( $data, 10 );
00042         foreach ( $tests as $key ) {
00043             $this->assertSame(
00044                 $data[$key],
00045                 $mi->get( $key ),
00046                 "Values are preserved for random key $key"
00047             );
00048         }
00049 
00050         $cached = $mi->retrieve();
00051 
00052         $tests = array_rand( $data, 10 );
00053         foreach ( $tests as $key ) {
00054             $this->assertSame(
00055                 $data[$key],
00056                 $mi->get( $key ),
00057                 "Values are preserved after retrieve for random key $key"
00058             );
00059         }
00060 
00061         $this->assertEquals(
00062             count( $data ),
00063             count( $cached ),
00064             'Cache has same number of elements'
00065         );
00066         $this->assertEquals( $data, $cached, 'Cache is preserved' );
00067     }
00068 
00069     public static function provideMessageIndexImplementation() {
00070         return array(
00071             array( new TestableDatabaseMessageIndex() ),
00072             array( new TestableCDBMessageIndex() ),
00073             array( new TestableSerializedMessageIndex() ),
00074             // Not testing CachedMessageIndex because there is no easy way to mockup those.
00075         );
00076     }
00077 }
00078 
00079 class TestableDatabaseMessageIndex extends DatabaseMessageIndex {
00080     // @codingStandardsIgnoreStart PHP CodeSniffer warns "Useless method overriding
00081     // detected", but store() and get() are protected in parent.
00082     public function store( array $a ) {
00083         parent::store( $a );
00084     }
00085 
00086     public function get( $a ) {
00087         return parent::get( $a );
00088     } // @codingStandardsIgnoreEnd
00089 }
00090 
00091 class TestableCDBMessageIndex extends CDBMessageIndex {
00092     // @codingStandardsIgnoreStart PHP CodeSniffer warns "Useless method overriding
00093     // detected", but store() and get() are protected in parent.
00094     public function store( array $a ) {
00095         parent::store( $a );
00096     }
00097 
00098     public function get( $a ) {
00099         return parent::get( $a );
00100     } // @codingStandardsIgnoreEnd
00101 }
00102 
00103 class TestableSerializedMessageIndex extends SerializedMessageIndex {
00104     // @codingStandardsIgnoreStart PHP CodeSniffer warns "Useless method overriding
00105     // detected", but store() and get() are protected in parent.
00106     public function store( array $a ) {
00107         parent::store( $a );
00108     }
00109 
00110     public function get( $a ) {
00111         return parent::get( $a );
00112     } // @codingStandardsIgnoreEnd
00113 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3