Exemplo n.º 1
0
 /**
  * Checks that the saved field item value matches the expected one.
  *
  * @param \Drupal\entity_test\Entity\EntityTest $entity
  *   The test entity.
  * @param $expected_value
  *   The expected field item value.
  *
  * @return bool
  *   TRUE if the item value matches expectations, FALSE otherwise.
  */
 protected function assertSavedFieldItemValue(EntityTest $entity, $expected_value)
 {
     $entity->setNewRevision(TRUE);
     $entity->save();
     $base_field_expected_value = str_replace($this->fieldName, 'field_test_item', $expected_value);
     $result = $this->assertEqual($entity->field_test_item->value, $base_field_expected_value);
     $result = $result && $this->assertEqual($entity->{$this->fieldName}->value, $expected_value);
     $entity = $this->reloadEntity($entity);
     $result = $result && $this->assertEqual($entity->field_test_item->value, $base_field_expected_value);
     $result = $result && $this->assertEqual($entity->{$this->fieldName}->value, $expected_value);
     return $result;
 }
 /**
  * Test that comments correctly invalidate the cache tag of their host entity.
  */
 public function testCommentEntity()
 {
     $this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'MISS');
     $this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'HIT');
     // Create a "Hippopotamus" comment.
     $this->entityTestHippopotamidae = EntityTest::create(array('name' => 'Hippopotamus', 'type' => 'bar'));
     $this->entityTestHippopotamidae->save();
     $this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'MISS');
     $this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'HIT');
     $hippo_comment = Comment::create(array('subject' => 'Hippopotamus', 'comment_body' => array('value' => 'The common hippopotamus (Hippopotamus amphibius), or hippo, is a large, mostly herbivorous mammal in sub-Saharan Africa', 'format' => 'plain_text'), 'entity_id' => $this->entityTestHippopotamidae->id(), 'entity_type' => 'entity_test', 'field_name' => 'comment', 'status' => CommentInterface::PUBLISHED));
     $hippo_comment->save();
     // Ensure that a new comment only invalidates the commented entity.
     $this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'HIT');
     $this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'MISS');
     $this->assertText($hippo_comment->getSubject());
     // Ensure that updating an existing comment only invalidates the commented
     // entity.
     $this->entity->save();
     $this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'MISS');
     $this->verifyPageCache($this->entityTestHippopotamidae->urlInfo(), 'HIT');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('system_breadcrumb_block');
     // Create a bundle for entity_test.
     entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test');
     entity_create('comment_type', array('id' => 'comment', 'label' => 'Comment settings', 'description' => 'Comment settings', 'target_entity_type_id' => 'entity_test'))->save();
     // Create comment field on entity_test bundle.
     $this->addDefaultCommentField('entity_test', 'entity_test');
     // Verify that bundles are defined correctly.
     $bundles = \Drupal::entityManager()->getBundleInfo('comment');
     $this->assertEqual($bundles['comment']['label'], 'Comment settings');
     // Create test user.
     $this->adminUser = $this->drupalCreateUser(array('administer comments', 'skip comment approval', 'post comments', 'access comments', 'view test entity', 'administer entity_test content'));
     // Enable anonymous and authenticated user comments.
     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access comments', 'post comments', 'skip comment approval'));
     user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access comments', 'post comments', 'skip comment approval'));
     // Create a test entity.
     $random_label = $this->randomMachineName();
     $data = array('type' => 'entity_test', 'name' => $random_label);
     $this->entity = entity_create('entity_test', $data);
     $this->entity->save();
 }
Exemplo n.º 4
0
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $this->installEntitySchema($this->entityTypeId);
    $this->installEntitySchema('filter_format');

    // Setup a field and an entity display.
    EntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => 'default',
    ])->save();
    FieldStorageConfig::create([
      'field_name' => $this->fieldName,
      'entity_type' => $this->entityTypeId,
      'type' => 'text',
    ])->save();
    FieldConfig::create([
      'entity_type' => $this->entityTypeId,
      'field_name' => $this->fieldName,
      'bundle' => $this->entityTypeId,
    ])->save();

    $this->entityViewDisplay = EntityViewDisplay::load('entity_test.entity_test.default');

    // Create a test entity with a test value.
    $this->entity = EntityTest::create();
    $this->entity->{$this->fieldName}->value = 'lorem ipsum';
    $this->entity->save();

    // Set the default filter format.
    FilterFormat::create([
      'format' => 'test_format',
      'name' => $this->randomMachineName(),
    ])->save();
    $this->container->get('config.factory')
      ->getEditable('filter.settings')
      ->set('fallback_format', 'test_format')
      ->save();
  }