/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->drupalPlaceBlock('local_tasks_block'); $this->drupalPlaceBlock('local_actions_block'); $this->drupalPlaceBlock('page_title_block'); $this->type = $this->createProfileType('test', 'Test profile', TRUE); $id = $this->type->id(); $field_storage = FieldStorageConfig::create(['field_name' => 'profile_fullname', 'entity_type' => 'profile', 'type' => 'text']); $field_storage->save(); $this->field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->type->id(), 'label' => 'Full name']); $this->field->save(); // Configure the default display. $this->display = EntityViewDisplay::load("profile.{$this->type->id()}.default"); if (!$this->display) { $this->display = EntityViewDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]); $this->display->save(); } $this->display->setComponent($this->field->getName(), ['type' => 'string'])->save(); // Configure rhe default form. $this->form = EntityFormDisplay::load("profile.{$this->type->id()}.default"); if (!$this->form) { $this->form = EntityFormDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]); $this->form->save(); } $this->form->setComponent($this->field->getName(), ['type' => 'string_textfield'])->save(); $this->checkPermissions(['administer profile types', "view own {$id} profile", "view any {$id} profile", "add own {$id} profile", "add any {$id} profile", "edit own {$id} profile", "edit any {$id} profile", "delete own {$id} profile", "delete any {$id} profile"]); user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['access user profiles']); $this->adminUser = $this->drupalCreateUser(['administer profile types', "view any {$id} profile", "add any {$id} profile", "edit any {$id} profile", "delete any {$id} profile"]); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installConfig(['system']); $this->installConfig(['field']); $this->installConfig(['text']); $this->installConfig(['address']); $this->installEntitySchema('entity_test'); ConfigurableLanguage::createFromLangcode('zh-hant')->save(); // The address module is never installed, so the importer doesn't run // automatically. Instead, we manually import the address formats we need. $country_codes = ['AD', 'SV', 'TW', 'US', 'ZZ']; $importer = \Drupal::service('address.address_format_importer'); $importer->importEntities($country_codes); $importer->importTranslations(['zh-hant']); $this->entityType = 'entity_test'; $this->bundle = $this->entityType; $this->fieldName = Unicode::strtolower($this->randomMachineName()); $field_storage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'address']); $field_storage->save(); $field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName()]); $field->save(); $values = ['targetEntityType' => $this->entityType, 'bundle' => $this->bundle, 'mode' => 'default', 'status' => TRUE]; $this->display = \Drupal::entityTypeManager()->getStorage('entity_view_display')->create($values); $this->display->setComponent($this->fieldName, ['type' => 'address_default', 'settings' => []]); $this->display->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installConfig(['field']); $this->installEntitySchema('entity_test'); $this->entityType = 'entity_test'; $this->bundle = $this->entityType; $this->fieldName = Unicode::strtolower($this->randomMachineName()); $field_storage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'boolean']); $field_storage->save(); $instance = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName()]); $instance->save(); $this->display = entity_get_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, ['type' => 'boolean', 'settings' => []]); $this->display->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installConfig(['field']); $this->installEntitySchema('entity_test'); $this->installEntitySchema('file'); $this->installSchema('file', array('file_usage')); $this->entityType = 'entity_test'; $this->bundle = $this->entityType; $this->fieldName = Unicode::strtolower($this->randomMachineName()); FieldStorageConfig::create(array('entity_type' => $this->entityType, 'field_name' => $this->fieldName, 'type' => 'image', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))->save(); FieldConfig::create(['entity_type' => $this->entityType, 'field_name' => $this->fieldName, 'bundle' => $this->bundle, 'settings' => ['file_extensions' => 'jpg']])->save(); $this->display = entity_get_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, ['type' => 'image', 'label' => 'hidden']); $this->display->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Configure the theme system. $this->installConfig(array('system', 'field')); $this->installEntitySchema('entity_test'); $this->entityType = 'entity_test'; $this->bundle = $this->entityType; $this->fieldName = Unicode::strtolower($this->randomMachineName()); $field_storage = FieldStorageConfig::create(array('field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'string')); $field_storage->save(); $instance = FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName())); $instance->save(); $this->display = entity_get_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, array('type' => 'string', 'settings' => array())); $this->display->save(); }
/** * Tests string formatter output. */ public function testStringFormatter() { $value = $this->randomString(); $value .= "\n\n<strong>" . $this->randomString() . '</strong>'; $value .= "\n\n" . $this->randomString(); $entity = EntityTestRev::create(array()); $entity->{$this->fieldName}->value = $value; // Verify that all HTML is escaped and newlines are retained. $this->renderEntityFields($entity, $this->display); $this->assertNoRaw($value); $this->assertRaw(nl2br(SafeMarkup::checkPlain($value))); // Verify the cache tags. $build = $entity->{$this->fieldName}->view(); $this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.'); $value = $this->randomMachineName(); $entity->{$this->fieldName}->value = $value; $entity->save(); // Set the formatter to link to the entity. $this->display->setComponent($this->fieldName, ['type' => 'string', 'settings' => ['link_to_entity' => TRUE]]); $this->display->save(); $this->renderEntityFields($entity, $this->display); $this->assertLink($value, 0); $this->assertLinkByHref($entity->url()); // $entity->url('revision') falls back to the canonical URL if this is no // revision. $this->assertLinkByHref($entity->url('revision')); // Make the entity a new revision. $old_revision_id = $entity->getRevisionId(); $entity->setNewRevision(TRUE); $value2 = $this->randomMachineName(); $entity->{$this->fieldName}->value = $value2; $entity->save(); $entity_new_revision = \Drupal::entityManager()->getStorage('entity_test_rev')->loadRevision($old_revision_id); $this->renderEntityFields($entity, $this->display); $this->assertLink($value2, 0); $this->assertLinkByHref($entity->url('revision')); $this->renderEntityFields($entity_new_revision, $this->display); $this->assertLink($value, 0); $this->assertLinkByHref('/entity_test_rev/' . $entity_new_revision->id() . '/revision/' . $entity_new_revision->getRevisionId() . '/view'); }
/** * Tests string formatter output. */ public function testStringFormatter() { $value = $this->randomString(); $value .= "\n\n<strong>" . $this->randomString() . '</strong>'; $value .= "\n\n" . $this->randomString(); $entity = EntityTest::create(array()); $entity->{$this->fieldName}->value = $value; // Verify that all HTML is escaped and newlines are retained. $this->renderEntityFields($entity, $this->display); $this->assertNoRaw($value); $this->assertRaw(nl2br(String::checkPlain($value))); // Verify the cache tags. $build = $entity->{$this->fieldName}->view(); $this->assertTrue(!isset($build[0]['#cache']), format_string('The string formatter has no cache tags.')); // Set the formatter to link to the entity. $this->display->setComponent($this->fieldName, ['type' => 'string', 'settings' => ['link_to_entity' => TRUE]]); $this->display->save(); $value = $this->randomMachineName(); $entity->{$this->fieldName}->value = $value; $entity->save(); $this->renderEntityFields($entity, $this->display); $this->assertLink($value, 0); $this->assertLinkByHref($entity->url()); }