SharedTempStore example

parent::setUp();

    $this->keyValue = $this->createMock('Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface');
    $this->lock = $this->createMock('Drupal\Core\Lock\LockBackendInterface');
    $this->requestStack = new RequestStack();
    $request = Request::createFromGlobals();
    $session = $this->createMock(SessionInterface::class);
    $request->setSession($session);
    $this->requestStack->push($request);
    $current_user = $this->createMock(AccountProxyInterface::class);

    $this->tempStore = new SharedTempStore($this->keyValue, $this->lock, $this->owner, $this->requestStack, $current_user, 604800);

    $this->ownObject = (object) [
      'data' => 'test_data',
      'owner' => $this->owner,
      'updated' => (int) $request->server->get('REQUEST_TIME'),
    ];

    // Clone the object but change the owner.     $this->otherObject = clone $this->ownObject;
    $this->otherObject->owner = 2;
  }

  
$owner = Crypt::randomBytesBase64();
        if ($this->requestStack->getCurrentRequest()->hasSession()) {
          // Store a random identifier for anonymous users if the session is           // available.           $owner = $this->requestStack->getCurrentRequest()->getSession()->get('core.tempstore.shared.owner', $owner);
        }
      }
    }

    // Store the data for this collection in the database.     $storage = $this->storageFactory->get("tempstore.shared.$collection");
    return new SharedTempStore($storage$this->lockBackend, $owner$this->requestStack, $this->currentUser, $this->expire);
  }

}
Home | Imprint | This part of the site doesn't use cookies.