Remove duplicate array keys from tests
[lhc/web/wiklou.git] / tests / phpunit / includes / session / SessionManagerTest.php
index dc217cd..d78e2b5 100644 (file)
@@ -182,7 +182,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                $session = $manager->getSessionForRequest( $request );
                $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
                $this->assertSame( $idEmpty, $session->getId() );
-               $this->assertNull( $manager->getPersistedSessionId( $request ) );
 
                // Both providers return info, picks best one
                $request->info1 = new SessionInfo( SessionInfo::MIN_PRIORITY + 1, array(
@@ -200,7 +199,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                $session = $manager->getSessionForRequest( $request );
                $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
                $this->assertSame( $id2, $session->getId() );
-               $this->assertSame( $id2, $manager->getPersistedSessionId( $request ) );
 
                $request->info1 = new SessionInfo( SessionInfo::MIN_PRIORITY + 2, array(
                        'provider' => $provider1,
@@ -217,7 +215,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                $session = $manager->getSessionForRequest( $request );
                $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
                $this->assertSame( $id1, $session->getId() );
-               $this->assertSame( $id1, $manager->getPersistedSessionId( $request ) );
 
                // Tied priorities
                $request->info1 = new SessionInfo( SessionInfo::MAX_PRIORITY, array(
@@ -246,18 +243,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                        $this->assertContains( $request->info1, $ex->sessionInfos );
                        $this->assertContains( $request->info2, $ex->sessionInfos );
                }
-               try {
-                       $manager->getPersistedSessionId( $request );
-                       $this->fail( 'Expcected exception not thrown' );
-               } catch ( \OverFlowException $ex ) {
-                       $this->assertStringStartsWith(
-                               'Multiple sessions for this request tied for top priority: ',
-                               $ex->getMessage()
-                       );
-                       $this->assertCount( 2, $ex->sessionInfos );
-                       $this->assertContains( $request->info1, $ex->sessionInfos );
-                       $this->assertContains( $request->info2, $ex->sessionInfos );
-               }
 
                // Bad provider
                $request->info1 = new SessionInfo( SessionInfo::MAX_PRIORITY, array(
@@ -276,15 +261,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                                $ex->getMessage()
                        );
                }
-               try {
-                       $manager->getPersistedSessionId( $request );
-                       $this->fail( 'Expcected exception not thrown' );
-               } catch ( \UnexpectedValueException $ex ) {
-                       $this->assertSame(
-                               'Provider1 returned session info for a different provider: ' . $request->info1,
-                               $ex->getMessage()
-                       );
-               }
 
                // Unusable session info
                $this->logger->setCollect( true );
@@ -304,7 +280,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                $session = $manager->getSessionForRequest( $request );
                $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
                $this->assertSame( $id2, $session->getId() );
-               $this->assertSame( $id2, $manager->getPersistedSessionId( $request ) );
                $this->logger->setCollect( false );
 
                // Unpersisted session ID
@@ -321,12 +296,10 @@ class SessionManagerTest extends MediaWikiTestCase {
                $this->assertSame( $id1, $session->getId() );
                $session->persist();
                $this->assertTrue( $session->isPersistent(), 'sanity check' );
-               $this->assertNull( $manager->getPersistedSessionId( $request ) );
        }
 
        public function testGetSessionById() {
                $manager = $this->getManager();
-
                try {
                        $manager->getSessionById( 'bad' );
                        $this->fail( 'Expected exception not thrown' );
@@ -336,39 +309,28 @@ class SessionManagerTest extends MediaWikiTestCase {
 
                // Unknown session ID
                $id = $manager->generateSessionId();
-               $session = $manager->getSessionById( $id );
+               $session = $manager->getSessionById( $id, true );
                $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
                $this->assertSame( $id, $session->getId() );
 
                $id = $manager->generateSessionId();
-               $this->assertNull( $manager->getSessionById( $id, true ) );
+               $this->assertNull( $manager->getSessionById( $id, false ) );
 
                // Known but unloadable session ID
                $this->logger->setCollect( true );
                $id = $manager->generateSessionId();
-               $this->store->setRawSession( $id, array( 'metadata' => array(
-                       'provider' => 'DummySessionProvider',
-                       'userId' => 0,
-                       'userName' => null,
-                       'userToken' => null,
+               $this->store->setSession( $id, array( 'metadata' => array(
+                       'userId' => User::idFromName( 'UTSysop' ),
+                       'userToken' => 'bad',
                ) ) );
 
-               try {
-                       $manager->getSessionById( $id );
-                       $this->fail( 'Expected exception not thrown' );
-               } catch ( \UnexpectedValueException $ex ) {
-                       $this->assertSame(
-                               'Can neither load the session nor create an empty session',
-                               $ex->getMessage()
-                       );
-               }
-
                $this->assertNull( $manager->getSessionById( $id, true ) );
+               $this->assertNull( $manager->getSessionById( $id, false ) );
                $this->logger->setCollect( false );
 
                // Known session ID
                $this->store->setSession( $id, array() );
-               $session = $manager->getSessionById( $id );
+               $session = $manager->getSessionById( $id, false );
                $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
                $this->assertSame( $id, $session->getId() );
        }
@@ -634,7 +596,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                        'Bar' => array( 'X', 'Bar1', 3 => 'Bar2' ),
                        'Quux' => array( 'Quux' ),
                        'Baz' => array(),
-                       'Quux' => array( 'Quux' ),
                );
 
                $this->assertEquals( $expect, $manager->getVaryHeaders() );
@@ -754,14 +715,14 @@ class SessionManagerTest extends MediaWikiTestCase {
                $sessionId = $session->getSessionId();
                $id = (string)$sessionId;
 
-               $this->assertSame( $sessionId, $manager->getSessionById( $id )->getSessionId() );
+               $this->assertSame( $sessionId, $manager->getSessionById( $id, true )->getSessionId() );
 
                $manager->changeBackendId( $backend );
                $this->assertSame( $sessionId, $session->getSessionId() );
                $this->assertNotEquals( $id, (string)$sessionId );
                $id = (string)$sessionId;
 
-               $this->assertSame( $sessionId, $manager->getSessionById( $id )->getSessionId() );
+               $this->assertSame( $sessionId, $manager->getSessionById( $id, true )->getSessionId() );
 
                // Destruction of the session here causes the backend to be deregistered
                $session = null;
@@ -784,7 +745,7 @@ class SessionManagerTest extends MediaWikiTestCase {
                        );
                }
 
-               $session = $manager->getSessionById( $id );
+               $session = $manager->getSessionById( $id, true );
                $this->assertSame( $sessionId, $session->getSessionId() );
        }
 
@@ -800,7 +761,7 @@ class SessionManagerTest extends MediaWikiTestCase {
 
                $that = $this;
 
-               \ObjectCache::$instances[__METHOD__] = new \HashBagOStuff();
+               \ObjectCache::$instances[__METHOD__] = new TestBagOStuff();
                $this->setMwGlobals( array( 'wgMainCacheType' => __METHOD__ ) );
 
                $this->stashMwGlobals( array( 'wgGroupPermissions' ) );
@@ -1641,6 +1602,38 @@ class SessionManagerTest extends MediaWikiTestCase {
                $this->assertTrue( $info->forceHTTPS() );
                $this->assertSame( array(), $logger->getBuffer() );
 
+               // "Persist" flag from session
+               $this->store->setSessionMeta( $id, $metadata );
+               $info = new SessionInfo( SessionInfo::MIN_PRIORITY, array(
+                       'provider' => $provider,
+                       'id' => $id,
+                       'userInfo' => $userInfo
+               ) );
+               $this->assertTrue( $loadSessionInfoFromStore( $info ) );
+               $this->assertFalse( $info->wasPersisted() );
+               $this->assertSame( array(), $logger->getBuffer() );
+
+               $this->store->setSessionMeta( $id, array( 'persisted' => true ) + $metadata );
+               $info = new SessionInfo( SessionInfo::MIN_PRIORITY, array(
+                       'provider' => $provider,
+                       'id' => $id,
+                       'userInfo' => $userInfo
+               ) );
+               $this->assertTrue( $loadSessionInfoFromStore( $info ) );
+               $this->assertTrue( $info->wasPersisted() );
+               $this->assertSame( array(), $logger->getBuffer() );
+
+               $this->store->setSessionMeta( $id, array( 'persisted' => false ) + $metadata );
+               $info = new SessionInfo( SessionInfo::MIN_PRIORITY, array(
+                       'provider' => $provider,
+                       'id' => $id,
+                       'userInfo' => $userInfo,
+                       'persisted' => true
+               ) );
+               $this->assertTrue( $loadSessionInfoFromStore( $info ) );
+               $this->assertTrue( $info->wasPersisted() );
+               $this->assertSame( array(), $logger->getBuffer() );
+
                // Provider refreshSessionInfo() returning false
                $info = new SessionInfo( SessionInfo::MIN_PRIORITY, array(
                        'provider' => $provider3,