Exemple #1
0
 /**
  * @covers ::deleteCache
  */
 public function testDeleteCache()
 {
     $form_build_id = 'the_form_build_id';
     $this->formCacheStore->expects($this->once())->method('delete')->with($form_build_id);
     $this->formStateCacheStore->expects($this->once())->method('delete')->with($form_build_id);
     $this->formCache->deleteCache($form_build_id);
 }
 /**
  * Tests the deleteIfOwner() method.
  *
  * @covers ::deleteIfOwner()
  */
 public function testDeleteIfOwner()
 {
     $this->lock->expects($this->once())->method('acquire')->with('test_2')->will($this->returnValue(TRUE));
     $this->keyValue->expects($this->at(0))->method('get')->with('test_1')->will($this->returnValue(FALSE));
     $this->keyValue->expects($this->at(1))->method('get')->with('test_2')->will($this->returnValue($this->ownObject));
     $this->keyValue->expects($this->at(2))->method('delete')->with('test_2');
     $this->keyValue->expects($this->at(3))->method('get')->with('test_3')->will($this->returnValue($this->otherObject));
     $this->assertTrue($this->tempStore->deleteIfOwner('test_1'));
     $this->assertTrue($this->tempStore->deleteIfOwner('test_2'));
     $this->assertFalse($this->tempStore->deleteIfOwner('test_3'));
 }
 /**
  * @covers ::setCache
  */
 public function testSetCacheImmutableForm()
 {
     $form_build_id = 'the_form_build_id';
     $form = ['#form_id' => 'the_form_id'];
     $form_state = new FormState();
     $this->formCacheStore->expects($this->once())->method('setWithExpire')->with($form_build_id, $form, $this->isType('int'));
     $form_state_data = $form_state->getCacheableArray();
     $form_state_data['build_info']['safe_strings'] = [];
     // Ensure that the form is marked immutable.
     $form_state_data['build_info']['immutable'] = TRUE;
     $this->formStateCacheStore->expects($this->once())->method('setWithExpire')->with($form_build_id, $form_state_data, $this->isType('int'));
     // Rebuild the FormCache with a config factory that will return a config
     // object with the internal page cache enabled.
     $this->configFactory = $this->getConfigFactoryStub(['system.performance' => ['cache.page.use_internal' => TRUE]]);
     $this->formCache = $this->getMockBuilder('Drupal\\Core\\Form\\FormCache')->setConstructorArgs([$this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory, $this->requestStack, $this->requestPolicy])->setMethods(['isPageCacheable'])->getMock();
     $this->formCache->expects($this->once())->method('isPageCacheable')->willReturn(TRUE);
     $this->formCache->setCache($form_build_id, $form, $form_state);
 }