Merge "RevisionStoreDbTestBase, remove redundant needsDB override"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / NameTableStoreTest.php
index b5b2e0d..1517964 100644 (file)
@@ -26,6 +26,10 @@ class NameTableStoreTest extends MediaWikiTestCase {
                parent::setUp();
        }
 
+       protected function addCoreDBData() {
+               // The default implementation causes the slot_roles to already have content. Skip that.
+       }
+
        private function populateTable( $values ) {
                $insertValues = [];
                foreach ( $values as $name ) {
@@ -139,6 +143,9 @@ class NameTableStoreTest extends MediaWikiTestCase {
                $name,
                $expectedId
        ) {
+               // Make sure the table is empty!
+               $this->truncateTable( 'slot_roles' );
+
                $this->populateTable( $existingValues );
                $store = $this->getNameTableSqlStore( $cacheBag, (int)$needsInsert, $selectCalls );
 
@@ -266,6 +273,21 @@ class NameTableStoreTest extends MediaWikiTestCase {
                $this->assertSame( $expected, TestingAccessWrapper::newFromObject( $store )->tableCache );
        }
 
+       public function testReloadMap() {
+               $this->populateTable( [ 'foo' ] );
+               $store = $this->getNameTableSqlStore( new HashBagOStuff(), 0, 2 );
+
+               // force load
+               $this->assertCount( 1, $store->getMap() );
+
+               // add more stuff to the table, so the cache gets out of sync
+               $this->populateTable( [ 'bar' ] );
+
+               $expected = [ 1 => 'foo', 2 => 'bar' ];
+               $this->assertSame( $expected, $store->reloadMap() );
+               $this->assertSame( $expected, $store->getMap() );
+       }
+
        public function testCacheRaceCondition() {
                $wanHashBag = new HashBagOStuff();
                $store1 = $this->getNameTableSqlStore( $wanHashBag, 1, 1 );