260 $builder = $this->getMockBuilder(
'DummySessionProvider' )
261 ->setMethods( [
'persistsSessionId',
'sessionIdWasReset' ] );
263 $this->provider = $builder->getMock();
264 $this->provider->expects( $this->any() )->method(
'persistsSessionId' )
265 ->will( $this->returnValue(
false ) );
266 $this->provider->expects( $this->never() )->method(
'sessionIdWasReset' );
267 $backend = $this->
getBackend( User::newFromName(
'UTSysop' ) );
268 $manager = \TestingAccessWrapper::newFromObject( $this->manager );
269 $sessionId = $backend->getSessionId();
271 $this->assertSame( self::SESSIONID, $backend->getId() );
272 $this->assertSame( $backend->getId(), $sessionId->getId() );
273 $this->assertSame( $id, session_id() );
274 $this->assertSame( $backend,
$manager->allSessionBackends[self::SESSIONID] );
276 $this->provider = $builder->getMock();
277 $this->provider->expects( $this->any() )->method(
'persistsSessionId' )
278 ->will( $this->returnValue(
true ) );
280 $this->provider->expects( $this->once() )->method(
'sessionIdWasReset' )
281 ->with( $this->identicalTo( $backend ), $this->identicalTo( self::SESSIONID ) );
282 $manager = \TestingAccessWrapper::newFromObject( $this->manager );
283 $sessionId = $backend->getSessionId();
285 $this->assertNotEquals( self::SESSIONID, $backend->getId() );
286 $this->assertSame( $backend->getId(), $sessionId->getId() );
287 $this->assertInternalType(
'array', $this->
store->getSession( $backend->getId() ) );
288 $this->assertFalse( $this->
store->getSession( self::SESSIONID ) );
289 $this->assertSame( $id, session_id() );
290 $this->assertArrayNotHasKey( self::SESSIONID,
$manager->allSessionBackends );
291 $this->assertArrayHasKey( $backend->getId(),
$manager->allSessionBackends );
292 $this->assertSame( $backend,
$manager->allSessionBackends[$backend->getId()] );
487 $user = static::getTestSysop()->getUser();
489 $testData = [
'foo' =>
'foo!',
'bar', [
'baz', null ] ];
491 $neverHook = $this->getMock( __CLASS__, [
'onSessionMetadata' ] );
492 $neverHook->expects( $this->never() )->method(
'onSessionMetadata' );
494 $builder = $this->getMockBuilder(
'DummySessionProvider' )
495 ->setMethods( [
'persistSession',
'unpersistSession' ] );
497 $neverProvider = $builder->getMock();
498 $neverProvider->expects( $this->never() )->method(
'persistSession' );
499 $neverProvider->expects( $this->never() )->method(
'unpersistSession' );
502 $this->provider = $neverProvider;
504 $this->
store->setSessionData( self::SESSIONID, $testData );
506 $this->
store->deleteSession( self::SESSIONID );
507 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
508 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
509 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
false;
511 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
514 $this->provider = $builder->getMock();
515 $this->provider->expects( $this->never() )->method(
'persistSession' );
516 $this->provider->expects( $this->atLeastOnce() )->method(
'unpersistSession' );
518 $this->
store->setSessionData( self::SESSIONID, $testData );
520 $this->
store->deleteSession( self::SESSIONID );
521 \TestingAccessWrapper::newFromObject( $backend )->persist =
false;
522 \TestingAccessWrapper::newFromObject( $backend )->forcePersist =
true;
523 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
524 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
525 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
false;
527 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
530 $this->provider = $neverProvider;
532 $this->
store->setSessionData( self::SESSIONID, $testData );
534 \TestingAccessWrapper::newFromObject( $backend )->requests[100]
536 $this->
store->deleteSession( self::SESSIONID );
537 \TestingAccessWrapper::newFromObject( $backend )->persist =
false;
538 \TestingAccessWrapper::newFromObject( $backend )->forcePersist =
true;
539 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
540 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
541 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
false;
543 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
546 $this->provider = $neverProvider;
547 $this->onSessionMetadataCalled =
false;
549 $this->
store->setSessionData( self::SESSIONID, $testData );
551 $this->
store->deleteSession( self::SESSIONID );
552 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
553 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
554 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
true;
556 $this->assertTrue( $this->onSessionMetadataCalled );
557 $blob = $this->
store->getSession( self::SESSIONID );
558 $this->assertInternalType(
'array',
$blob );
559 $this->assertArrayHasKey(
'metadata',
$blob );
560 $metadata =
$blob[
'metadata'];
561 $this->assertInternalType(
'array', $metadata );
562 $this->assertArrayHasKey(
'???', $metadata );
563 $this->assertSame(
'!!!', $metadata[
'???'] );
564 $this->assertFalse( $this->
store->getSessionFromBackend( self::SESSIONID ),
565 'making sure it didn\'t save to backend' );
568 $this->provider = $neverProvider;
570 $this->
store->setSessionData( self::SESSIONID, $testData );
572 $this->
store->deleteSession( self::SESSIONID );
573 \TestingAccessWrapper::newFromObject( $backend )->persist =
true;
574 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
575 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
576 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
false;
578 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
581 $this->provider = $builder->getMock();
582 $this->provider->expects( $this->atLeastOnce() )->method(
'persistSession' );
583 $this->provider->expects( $this->never() )->method(
'unpersistSession' );
585 $this->
store->setSessionData( self::SESSIONID, $testData );
587 $this->
store->deleteSession( self::SESSIONID );
588 \TestingAccessWrapper::newFromObject( $backend )->persist =
true;
589 \TestingAccessWrapper::newFromObject( $backend )->forcePersist =
true;
590 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
591 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
592 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
false;
594 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
597 $this->provider = $neverProvider;
598 $this->onSessionMetadataCalled =
false;
600 $this->
store->setSessionData( self::SESSIONID, $testData );
602 $this->
store->deleteSession( self::SESSIONID );
603 \TestingAccessWrapper::newFromObject( $backend )->persist =
true;
604 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
605 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
606 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
true;
608 $this->assertTrue( $this->onSessionMetadataCalled );
609 $blob = $this->
store->getSession( self::SESSIONID );
610 $this->assertInternalType(
'array',
$blob );
611 $this->assertArrayHasKey(
'metadata',
$blob );
612 $metadata =
$blob[
'metadata'];
613 $this->assertInternalType(
'array', $metadata );
614 $this->assertArrayHasKey(
'???', $metadata );
615 $this->assertSame(
'!!!', $metadata[
'???'] );
616 $this->assertNotSame(
false, $this->
store->getSessionFromBackend( self::SESSIONID ),
617 'making sure it did save to backend' );
620 $this->provider = $builder->getMock();
621 $this->provider->expects( $this->atLeastOnce() )->method(
'persistSession' );
622 $this->provider->expects( $this->never() )->method(
'unpersistSession' );
623 $this->onSessionMetadataCalled =
false;
625 $this->
store->setSessionData( self::SESSIONID, $testData );
627 $this->
store->deleteSession( self::SESSIONID );
628 \TestingAccessWrapper::newFromObject( $backend )->persist =
true;
629 \TestingAccessWrapper::newFromObject( $backend )->forcePersist =
true;
630 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
631 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
632 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
true;
634 $this->assertTrue( $this->onSessionMetadataCalled );
635 $blob = $this->
store->getSession( self::SESSIONID );
636 $this->assertInternalType(
'array',
$blob );
637 $this->assertArrayHasKey(
'metadata',
$blob );
638 $metadata =
$blob[
'metadata'];
639 $this->assertInternalType(
'array', $metadata );
640 $this->assertArrayHasKey(
'???', $metadata );
641 $this->assertSame(
'!!!', $metadata[
'???'] );
642 $this->assertNotSame(
false, $this->
store->getSessionFromBackend( self::SESSIONID ),
643 'making sure it did save to backend' );
646 $this->provider = $builder->getMock();
647 $this->provider->expects( $this->atLeastOnce() )->method(
'persistSession' );
648 $this->provider->expects( $this->never() )->method(
'unpersistSession' );
649 $this->onSessionMetadataCalled =
false;
651 $this->
store->setSessionData( self::SESSIONID, $testData );
653 $this->
store->deleteSession( self::SESSIONID );
654 \TestingAccessWrapper::newFromObject( $backend )->persist =
true;
655 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
656 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
true;
657 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
false;
659 $this->assertTrue( $this->onSessionMetadataCalled );
660 $blob = $this->
store->getSession( self::SESSIONID );
661 $this->assertInternalType(
'array',
$blob );
662 $this->assertArrayHasKey(
'metadata',
$blob );
663 $metadata =
$blob[
'metadata'];
664 $this->assertInternalType(
'array', $metadata );
665 $this->assertArrayHasKey(
'???', $metadata );
666 $this->assertSame(
'!!!', $metadata[
'???'] );
667 $this->assertNotSame(
false, $this->
store->getSessionFromBackend( self::SESSIONID ),
668 'making sure it did save to backend' );
672 $this->provider = $neverProvider;
673 $this->onSessionMetadataCalled =
false;
675 $this->
store->setSessionData( self::SESSIONID, $testData );
677 $this->
store->deleteSession( self::SESSIONID );
678 \TestingAccessWrapper::newFromObject( $backend )->persist =
true;
679 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
680 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
false;
681 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
false;
682 \TestingAccessWrapper::newFromObject( $backend )->dataHash =
'Doesn\'t match';
684 $this->assertTrue( $this->onSessionMetadataCalled );
685 $blob = $this->
store->getSession( self::SESSIONID );
686 $this->assertInternalType(
'array',
$blob );
687 $this->assertArrayHasKey(
'metadata',
$blob );
688 $metadata =
$blob[
'metadata'];
689 $this->assertInternalType(
'array', $metadata );
690 $this->assertArrayHasKey(
'???', $metadata );
691 $this->assertSame(
'!!!', $metadata[
'???'] );
692 $this->assertNotSame(
false, $this->
store->getSessionFromBackend( self::SESSIONID ),
693 'making sure it did save to backend' );
696 $this->provider =
null;
697 $mockHook = $this->getMock( __CLASS__, [
'onSessionMetadata' ] );
698 $mockHook->expects( $this->any() )->method(
'onSessionMetadata' )
699 ->will( $this->returnCallback(
701 $metadata[
'userId']++;
705 $this->
store->setSessionData( self::SESSIONID, $testData );
710 $this->fail(
'Expected exception not thrown' );
711 }
catch ( \UnexpectedValueException $ex ) {
713 'SessionMetadata hook changed metadata key "userId"',
719 \TestingAccessWrapper::newFromObject( $this->manager )->preventUsers = [
720 $user->getName() =>
true,
722 $this->provider = $neverProvider;
724 $this->
store->setSessionData( self::SESSIONID, $testData );
726 $this->
store->deleteSession( self::SESSIONID );
727 \TestingAccessWrapper::newFromObject( $backend )->persist =
true;
728 $this->assertTrue( $backend->
isPersistent(),
'sanity check' );
729 \TestingAccessWrapper::newFromObject( $backend )->metaDirty =
true;
730 \TestingAccessWrapper::newFromObject( $backend )->dataDirty =
true;
732 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
736 $user = static::getTestSysop()->getUser();
738 $testData = [
'foo' =>
'foo!',
'bar', [
'baz', null ] ];
741 $this->provider = $this->getMock(
'DummySessionProvider', [
'persistSession' ] );
742 $this->provider->expects( $this->never() )->method(
'persistSession' );
743 $this->onSessionMetadataCalled =
false;
745 $this->
store->setSessionData( self::SESSIONID, $testData );
747 $this->
store->deleteSession( self::SESSIONID );
748 $wrap = \TestingAccessWrapper::newFromObject( $backend );
749 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
750 $wrap->metaDirty =
false;
751 $wrap->dataDirty =
false;
752 $wrap->forcePersist =
false;
755 $this->assertTrue( $this->onSessionMetadataCalled );
756 $blob = $this->
store->getSession( self::SESSIONID );
757 $this->assertInternalType(
'array',
$blob );
758 $this->assertArrayHasKey(
'metadata',
$blob );
759 $metadata =
$blob[
'metadata'];
760 $this->assertInternalType(
'array', $metadata );
761 $this->assertArrayHasKey(
'???', $metadata );
762 $this->assertSame(
'!!!', $metadata[
'???'] );
763 $this->assertNotEquals( 0, $wrap->expires );
766 $this->provider = $this->getMock(
'DummySessionProvider', [
'persistSession' ] );
767 $this->provider->expects( $this->atLeastOnce() )->method(
'persistSession' );
768 $this->onSessionMetadataCalled =
false;
770 $this->
store->setSessionData( self::SESSIONID, $testData );
772 $this->
store->deleteSession( self::SESSIONID );
773 $wrap = \TestingAccessWrapper::newFromObject( $backend );
774 $wrap->persist =
true;
775 $this->assertTrue( $backend->isPersistent(),
'sanity check' );
776 $wrap->metaDirty =
false;
777 $wrap->dataDirty =
false;
778 $wrap->forcePersist =
false;
781 $this->assertTrue( $this->onSessionMetadataCalled );
782 $blob = $this->
store->getSession( self::SESSIONID );
783 $this->assertInternalType(
'array',
$blob );
784 $this->assertArrayHasKey(
'metadata',
$blob );
785 $metadata =
$blob[
'metadata'];
786 $this->assertInternalType(
'array', $metadata );
787 $this->assertArrayHasKey(
'???', $metadata );
788 $this->assertSame(
'!!!', $metadata[
'???'] );
789 $this->assertNotEquals( 0, $wrap->expires );
792 $this->provider = $this->getMock(
'DummySessionProvider', [
'persistSession' ] );
793 $this->provider->expects( $this->never() )->method(
'persistSession' );
794 $this->onSessionMetadataCalled =
false;
796 $this->
store->setSessionData( self::SESSIONID, $testData );
798 $this->
store->deleteSession( self::SESSIONID );
799 $wrap = \TestingAccessWrapper::newFromObject( $backend );
800 $this->assertFalse( $backend->isPersistent(),
'sanity check' );
801 $wrap->metaDirty =
false;
802 $wrap->dataDirty =
false;
803 $wrap->forcePersist =
false;
804 $expires = time() + $wrap->lifetime + 100;
805 $wrap->expires = $expires;
807 $this->assertFalse( $this->onSessionMetadataCalled );
808 $this->assertFalse( $this->
store->getSession( self::SESSIONID ),
'making sure it didn\'t save' );
809 $this->assertEquals( $expires, $wrap->expires );