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


PHP EntityTest::loadMultiple方法代码示例

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


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

示例1: testEntityOperations

 /**
  * Tests entity operations field.
  */
 public function testEntityOperations()
 {
     // Create some test entities.
     for ($i = 0; $i < 5; $i++) {
         EntityTest::create(array('name' => $this->randomString()))->save();
     }
     $entities = EntityTest::loadMultiple();
     $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer entity_test content'));
     $this->drupalLogin($admin_user);
     $this->drupalGet('test-entity-operations');
     foreach ($entities as $entity) {
         $operations = \Drupal::entityManager()->getListBuilder('entity_test')->getOperations($entity);
         foreach ($operations as $operation) {
             $expected_destination = Url::fromUri('internal:/test-entity-operations')->toString();
             $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', array(':path' => $operation['url']->toString() . '?destination=' . $expected_destination, ':title' => $operation['title']));
             $this->assertEqual(count($result), 1, t('Found entity @operation link with destination parameter.', array('@operation' => $operation['title'])));
         }
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:FieldEntityOperationsTest.php

示例2: doTestEntityLink

 /**
  * Tests whether entity links behave as expected.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The user account to be used to run the test;
  * @param bool[] $expected_results
  *   An associative array of expected results keyed by link template name.
  */
 protected function doTestEntityLink(AccountInterface $account, $expected_results)
 {
     \Drupal::currentUser()->setAccount($account);
     $view = Views::getView('test_entity_test_link');
     $view->preview();
     $info = ['canonical' => ['label' => 'View entity test', 'field_id' => 'view_entity_test', 'destination' => FALSE], 'edit-form' => ['label' => 'Edit entity test', 'field_id' => 'edit_entity_test', 'destination' => TRUE], 'delete-form' => ['label' => 'Delete entity test', 'field_id' => 'delete_entity_test', 'destination' => TRUE]];
     $index = 0;
     foreach (EntityTest::loadMultiple() as $entity) {
         foreach ($expected_results as $template => $expected_result) {
             $expected_link = '';
             if ($expected_result) {
                 $path = $entity->url($template);
                 $destination = $info[$template]['destination'] ? '?destination=/' : '';
                 $expected_link = '<a href="' . $path . $destination . '" hreflang="en">' . $info[$template]['label'] . '</a>';
             }
             $link = $view->style_plugin->getField($index, $info[$template]['field_id']);
             $this->assertEqual($link, $expected_link);
         }
         $index++;
     }
 }
开发者ID:scratch,项目名称:gai,代码行数:29,代码来源:FieldEntityLinkTest.php

示例3: testCreateEntityTest

 /**
  * Tests valid and invalid create requests for 'entity_test' entity type.
  */
 public function testCreateEntityTest()
 {
     $entity_type = 'entity_test';
     // Enables the REST service for 'entity_test' entity type.
     $this->enableService('entity:' . $entity_type, 'POST');
     // Create two accounts with the required permissions to create resources.
     // The second one has administrative permissions.
     $accounts = $this->createAccountPerEntity($entity_type);
     // Verify create requests per user.
     foreach ($accounts as $key => $account) {
         $this->drupalLogin($account);
         // Populate some entity properties before create the entity.
         $entity_values = $this->entityValues($entity_type);
         $entity = EntityTest::create($entity_values);
         // Serialize the entity before the POST request.
         $serialized = $this->serializer->serialize($entity, $this->defaultFormat, ['account' => $account]);
         // Create the entity over the REST API.
         $this->assertCreateEntityOverRestApi($entity_type, $serialized);
         // Get the entity ID from the location header and try to read it from the
         // database.
         $this->assertReadEntityIdFromHeaderAndDb($entity_type, $entity, $entity_values);
         // Try to create an entity with an access protected field.
         // @see entity_test_entity_field_access()
         $normalized = $this->serializer->normalize($entity, $this->defaultFormat, ['account' => $account]);
         $normalized['field_test_text'][0]['value'] = 'no access value';
         $this->httpRequest('entity/' . $entity_type, 'POST', $this->serializer->serialize($normalized, $this->defaultFormat, ['account' => $account]), $this->defaultMimeType);
         $this->assertResponse(403);
         $this->assertFalse(EntityTest::loadMultiple(), 'No entity has been created in the database.');
         // Try to create a field with a text format this user has no access to.
         $entity->field_test_text->value = $entity_values['field_test_text'][0]['value'];
         $entity->field_test_text->format = 'full_html';
         $serialized = $this->serializer->serialize($entity, $this->defaultFormat, ['account' => $account]);
         $this->httpRequest('entity/' . $entity_type, 'POST', $serialized, $this->defaultMimeType);
         // The value selected is not a valid choice because the format must be
         // 'plain_txt'.
         $this->assertResponse(422);
         $this->assertFalse(EntityTest::loadMultiple(), 'No entity has been created in the database.');
         // Restore the valid test value.
         $entity->field_test_text->format = 'plain_text';
         $serialized = $this->serializer->serialize($entity, $this->defaultFormat, ['account' => $account]);
         // Try to send invalid data that cannot be correctly deserialized.
         $this->assertCreateEntityInvalidData($entity_type);
         // Try to send no data at all, which does not make sense on POST requests.
         $this->assertCreateEntityNoData($entity_type);
         // Try to send invalid data to trigger the entity validation constraints.
         // Send a UUID that is too long.
         $this->assertCreateEntityInvalidSerialized($entity, $entity_type);
         // Try to create an entity without proper permissions.
         $this->assertCreateEntityWithoutProperPermissions($entity_type, $serialized, ['account' => $account]);
     }
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:54,代码来源:CreateTest.php


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