當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ContentEntityBase::id方法代碼示例

本文整理匯總了PHP中Drupal\Core\Entity\ContentEntityBase::id方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContentEntityBase::id方法的具體用法?PHP ContentEntityBase::id怎麽用?PHP ContentEntityBase::id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Entity\ContentEntityBase的用法示例。


在下文中一共展示了ContentEntityBase::id方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testSerialize

 /**
  * Test registered Serializer's entity serialization for core's formats.
  */
 public function testSerialize()
 {
     // Test that Serializer responds using the ComplexDataNormalizer and
     // JsonEncoder. The output of ComplexDataNormalizer::normalize() is tested
     // elsewhere, so we can just assume that it works properly here.
     $normalized = $this->serializer->normalize($this->entity, 'json');
     $expected = json_encode($normalized);
     // Test 'json'.
     $actual = $this->serializer->serialize($this->entity, 'json');
     $this->assertIdentical($actual, $expected, 'Entity serializes to JSON when "json" is requested.');
     $actual = $this->serializer->serialize($normalized, 'json');
     $this->assertIdentical($actual, $expected, 'A normalized array serializes to JSON when "json" is requested');
     // Test 'ajax'.
     $actual = $this->serializer->serialize($this->entity, 'ajax');
     $this->assertIdentical($actual, $expected, 'Entity serializes to JSON when "ajax" is requested.');
     $actual = $this->serializer->serialize($normalized, 'ajax');
     $this->assertIdentical($actual, $expected, 'A normalized array serializes to JSON when "ajax" is requested');
     // Generate the expected xml in a way that allows changes to entity property
     // order.
     $expected = array('id' => '<id><value>' . $this->entity->id() . '</value></id>', 'uuid' => '<uuid><value>' . $this->entity->uuid() . '</value></uuid>', 'langcode' => '<langcode><value>' . LanguageInterface::LANGCODE_NOT_SPECIFIED . '</value></langcode>', 'name' => '<name><value>' . $this->values['name'] . '</value></name>', 'type' => '<type><value>entity_test_mulrev</value></type>', 'user_id' => '<user_id><target_id>' . $this->values['user_id'] . '</target_id></user_id>', 'revision_id' => '<revision_id><value>' . $this->entity->getRevisionId() . '</value></revision_id>', 'field_test_text' => '<field_test_text><value>' . $this->values['field_test_text']['value'] . '</value><format>' . $this->values['field_test_text']['format'] . '</format></field_test_text>');
     // Sort it in the same order as normalised.
     $expected = array_merge($normalized, $expected);
     // Add header and footer.
     array_unshift($expected, '<?xml version="1.0"?>' . PHP_EOL . '<response>');
     $expected[] = '</response>' . PHP_EOL;
     // Reduced the array to a string.
     $expected = implode('', $expected);
     // Test 'xml'. The output should match that of Symfony's XmlEncoder.
     $actual = $this->serializer->serialize($this->entity, 'xml');
     $this->assertIdentical($actual, $expected);
     $actual = $this->serializer->serialize($normalized, 'xml');
     $this->assertIdentical($actual, $expected);
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:36,代碼來源:EntitySerializationTest.php


注:本文中的Drupal\Core\Entity\ContentEntityBase::id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。