当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityStorageInterface::resetCache方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\EntityStorageInterface::resetCache方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityStorageInterface::resetCache方法的具体用法?PHP EntityStorageInterface::resetCache怎么用?PHP EntityStorageInterface::resetCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\EntityStorageInterface的用法示例。


在下文中一共展示了EntityStorageInterface::resetCache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCRUD

 /**
  * Tests CRUD.
  */
 public function testCRUD()
 {
     /** @var \Drupal\node\NodeInterface $node */
     /** @var \Drupal\field_collection\FieldCollectionItemInterface $field_collection_item */
     list($node, $field_collection_item) = $this->createNodeWithFieldCollection('article');
     $this->assertEqual($field_collection_item->id(), $node->{$this->field_collection_name}->value);
     $this->assertEqual($field_collection_item->revision_id->value, $node->{$this->field_collection_name}->revision_id);
     // Test adding an additional field_collection_item.
     $field_collection_item_2 = FieldCollectionItem::create(['field_name' => $this->field_collection_name]);
     $field_collection_item_2->{$this->inner_field_name}->setValue(2);
     $node->{$this->field_collection_name}[1] = array('field_collection_item' => $field_collection_item_2);
     $node->save();
     $this->nodeStorage->resetCache([$node->id()]);
     $node = Node::load($node->id());
     $this->assertTrue(!empty($field_collection_item_2->id()) && !empty($field_collection_item_2->getRevisionId()));
     $this->assertEqual(count(FieldCollectionItem::loadMultiple()), 2);
     $this->assertEqual($field_collection_item->id(), $node->{$this->field_collection_name}->value);
     $this->assertEqual($field_collection_item->getRevisionId(), $node->{$this->field_collection_name}[0]->revision_id);
     $this->assertEqual($field_collection_item_2->id(), $node->{$this->field_collection_name}[1]->value);
     $this->assertEqual($field_collection_item_2->getRevisionId(), $node->{$this->field_collection_name}[1]->revision_id);
     // Make sure deleting the field collection item removes the reference.
     $field_collection_item_2->delete();
     $this->nodeStorage->resetCache([$node->id()]);
     $node = Node::load($node->id());
     $this->assertTrue(!isset($node->{$this->field_collection_name}[1]));
     // Make sure field_collections are removed during deletion of the host.
     $node->delete();
     $this->assertIdentical(FieldCollectionItem::loadMultiple(), array());
     // Try deleting nodes with collections without any values.
     $node = $this->drupalCreateNode(array('type' => 'article'));
     $node->delete();
     $this->nodeStorage->resetCache([$node->id()]);
     $node = Node::load($node->id());
     $this->assertFalse($node);
     // Test creating a field collection entity with a not-yet saved host entity.
     $node = $this->drupalCreateNode(array('type' => 'article'));
     $field_collection_item = FieldCollectionItem::create(['field_name' => $this->field_collection_name]);
     $field_collection_item->{$this->inner_field_name}->setValue(3);
     $field_collection_item->setHostEntity($node);
     $field_collection_item->save();
     // Now the node should have been saved with the collection and the link
     // should have been established.
     $this->assertTrue(!empty($node->id()));
     $this->assertTrue(count($node->{$this->field_collection_name}) == 1 && !empty($node->{$this->field_collection_name}[0]->value) && !empty($node->{$this->field_collection_name}[0]->revision_id));
     // Again, test creating a field collection with a not-yet saved host entity,
     // but this time save both entities via the host.
     $node = $this->drupalCreateNode(array('type' => 'article'));
     $field_collection_item = FieldCollectionItem::create(array('field_name' => $this->field_collection_name));
     $field_collection_item->{$this->inner_field_name}->setValue(4);
     $field_collection_item->setHostEntity($node);
     $node->save();
     $this->assertTrue(!empty($field_collection_item->id()) && !empty($field_collection_item->getRevisionId()));
     $this->assertTrue(count($node->{$this->field_collection_name}) == 1 && !empty($node->{$this->field_collection_name}[0]->value) && !empty($node->{$this->field_collection_name}[0]->revision_id));
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:57,代码来源:FieldCollectionBasicTestCase.php

示例2: deleteServer

 /**
  * Tests deleting a search server via the UI.
  */
 protected function deleteServer()
 {
     $server = Server::load($this->serverId);
     // Load confirmation form.
     $this->drupalGet('admin/config/search/search-api/server/' . $this->serverId . '/delete');
     $this->assertResponse(200, 'Server delete page exists');
     $this->assertRaw(t('Are you sure you want to delete the search server %name?', array('%name' => $server->label())), 'Deleting a server sks for confirmation.');
     $this->assertText(t('Deleting a server will disable all its indexes and their searches.'), 'Correct warning is displayed when deleting a server.');
     // Confirm deletion.
     $this->drupalPostForm(NULL, NULL, t('Delete'));
     $this->assertRaw(t('The search server %name has been deleted.', array('%name' => $server->label())), 'The server was deleted.');
     $this->assertFalse(Server::load($this->serverId), 'Server could not be found anymore.');
     $this->assertUrl('admin/config/search/search-api', array(), 'Correct redirect to search api overview page.');
     // Confirm that the index hasn't been deleted.
     $this->indexStorage->resetCache(array($this->indexId));
     /** @var $index \Drupal\search_api\IndexInterface */
     $index = $this->indexStorage->load($this->indexId);
     if ($this->assertTrue($index, 'The index associated with the server was not deleted.')) {
         $this->assertFalse($index->status(), 'The index associated with the server was disabled.');
         $this->assertNull($index->getServerId(), 'The index was removed from the server.');
     }
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:25,代码来源:IntegrationTest.php


注:本文中的Drupal\Core\Entity\EntityStorageInterface::resetCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。