/**
  * Prepare a node to get suggestions from.
  *
  * Creates a node with two file fields. The first one is not translatable,
  * the second one is. Both fields got two files attached, where one has
  * translatable content (title and atl-text) and the other one not.
  *
  * @return object
  *   The node which is prepared with all needed fields for the suggestions.
  */
 protected function prepareTranslationSuggestions()
 {
     // Create a content type with fields.
     // Only the first field is a translatable reference.
     $type = NodeType::create(['type' => $this->randomMachineName()]);
     $type->save();
     $content_translation_manager = \Drupal::service('content_translation.manager');
     $content_translation_manager->setEnabled('node', $type->id(), TRUE);
     $field1 = FieldStorageConfig::create(array('field_name' => 'field1', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field1->save();
     $field2 = FieldStorageConfig::create(array('field_name' => 'field2', 'entity_type' => 'node', 'type' => 'entity_reference', 'cardinality' => -1, 'settings' => array('target_type' => 'node')));
     $field2->save();
     // Create field instances on the content type.
     FieldConfig::create(array('field_storage' => $field1, 'bundle' => $type->id(), 'label' => 'Field 1', 'translatable' => FALSE, 'settings' => array()))->save();
     FieldConfig::create(array('field_storage' => $field2, 'bundle' => $type->id(), 'label' => 'Field 2', 'translatable' => TRUE, 'settings' => array()))->save();
     // Create a translatable body field.
     node_add_body_field($type);
     $field = FieldConfig::loadByName('node', $type->id(), 'body');
     $field->setTranslatable(TRUE);
     $field->save();
     // Create 4 nodes to be referenced.
     $references = array();
     for ($i = 0; $i < 4; $i++) {
         $references[$i] = Node::create(array('title' => $this->randomMachineName(), 'body' => $this->randomMachineName(), 'type' => $type->id()));
         $references[$i]->save();
     }
     // Create a node with two translatable and two non-translatable references.
     $node = Node::create(array('title' => $this->randomMachineName(), 'type' => $type->id(), 'language' => 'en', 'body' => $this->randomMachineName(), $field1->getName() => array(array('target_id' => $references[0]->id()), array('target_id' => $references[1]->id())), $field2->getName() => array(array('target_id' => $references[2]->id()), array('target_id' => $references[3]->id()))));
     $node->save();
     $link = MenuLinkContent::create(['link' => [['uri' => 'entity:node/' . $node->id()]], 'title' => 'Node menu link', 'menu_name' => 'main']);
     $link->save();
     $node->link = $link;
     return $node;
 }
  public function setUp() {
    parent::setup();

    $this->installConfig(array('pathauto', 'taxonomy', 'system', 'node'));

    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installEntitySchema('taxonomy_term');

    ConfigurableLanguage::createFromLangcode('fr')->save();

    $this->installSchema('node', array('node_access'));
    $this->installSchema('system', array('url_alias', 'sequences', 'router'));

    $type = NodeType::create(['type' => 'page']);
    $type->save();
    node_add_body_field($type);

    $this->nodePattern = $this->createPattern('node', '/content/[node:title]');
    $this->userPattern = $this->createPattern('user', '/users/[user:name]');

    \Drupal::service('router.builder')->rebuild();

    $this->currentUser = entity_create('user', array('name' => $this->randomMachineName()));
    $this->currentUser->save();
  }
 /**
  * Create a petition content type and webform user enable it.
  */
 protected function webformUserCreateType()
 {
     $type = node_type_set_defaults();
     $type->name = t('Petition');
     $type->type = 'petition';
     $type->description = t('Webform user petition type.');
     $type->title_label = t('Title');
     $type->has_title = $type->title_label != '';
     $type->base = 'node_content';
     $type->custom = TRUE;
     $type->modified = TRUE;
     // Save or reset persistent variable values.
     $variables = array('node_submitted' => 0, 'comment' => COMMENT_NODE_HIDDEN, 'webform_user' => 1, 'webform_user_default_fields' => array('webform_user_all_profile_fields' => 'webform_user_all_profile_fields'));
     foreach ($variables as $key => $value) {
         $variable_new = $key . '_' . $type->type;
         if (is_array($value)) {
             $value = array_keys(array_filter($value));
         }
         variable_set($variable_new, $value);
     }
     $status = node_type_save($type);
     node_types_rebuild();
     node_add_body_field($type);
     // Add as a webform.
     $webform_node_types = variable_get('webform_node_types', array('webform'));
     $webform_node_types_primary = variable_get('webform_node_types_primary', array('webform'));
     $webform_node_types = array_merge($webform_node_types, array('petition'));
     $webform_node_types_primary = array_merge($webform_node_types_primary, array('petition'));
     variable_set('webform_node_types', array_unique($webform_node_types));
     variable_set('webform_node_types_primary', array_unique($webform_node_types_primary));
 }
 public function testRecreateEntity()
 {
     $type_name = Unicode::strtolower($this->randomMachineName(16));
     $content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type one'));
     $content_type->save();
     node_add_body_field($content_type);
     /** @var \Drupal\Core\Config\StorageInterface $active */
     $active = $this->container->get('config.storage');
     /** @var \Drupal\Core\Config\StorageInterface $sync */
     $sync = $this->container->get('config.storage.sync');
     $config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
     $this->copyConfig($active, $sync);
     // Delete the content type. This will also delete a field storage, a field,
     // an entity view display and an entity form display.
     $content_type->delete();
     $this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
     // Recreate with the same type - this will have a different UUID.
     $content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type two'));
     $content_type->save();
     node_add_body_field($content_type);
     $this->configImporter->reset();
     // A node type, a field, an entity view display and an entity form display
     // will be recreated.
     $creates = $this->configImporter->getUnprocessedConfiguration('create');
     $deletes = $this->configImporter->getUnprocessedConfiguration('delete');
     $this->assertEqual(5, count($creates), 'There are 5 configuration items to create.');
     $this->assertEqual(5, count($deletes), 'There are 5 configuration items to delete.');
     $this->assertEqual(0, count($this->configImporter->getUnprocessedConfiguration('update')), 'There are no configuration items to update.');
     $this->assertIdentical($creates, array_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');
     $this->configImporter->import();
     // Verify that there is nothing more to import.
     $this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
     $content_type = NodeType::load($type_name);
     $this->assertEqual('Node type one', $content_type->label());
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installConfig(['node']);
     $this->installSchema('node', ['node_access']);
     $this->installSchema('system', ['sequences']);
     // Create a new user which needs to have UID 1, because that is expected by
     // the assertions from
     // \Drupal\migrate_drupal\Tests\d6\MigrateNodeRevisionTest.
     User::create(['uid' => 1, 'name' => $this->randomMachineName(), 'status' => 1])->enforceIsNew(TRUE)->save();
     $node_type = entity_create('node_type', array('type' => 'test_planet'));
     $node_type->save();
     node_add_body_field($node_type);
     $node_type = entity_create('node_type', array('type' => 'story'));
     $node_type->save();
     node_add_body_field($node_type);
     $id_mappings = array('d6_node_type' => array(array(array('test_story'), array('story'))), 'd6_filter_format' => array(array(array(1), array('filtered_html')), array(array(2), array('full_html'))), 'd6_user' => array(array(array(1), array(1)), array(array(2), array(2))), 'd6_field_instance_widget_settings' => array(array(array('page', 'field_test'), array('node', 'page', 'default', 'test'))), 'd6_field_formatter_settings' => array(array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test'))));
     $this->prepareMigrations($id_mappings);
     $migration = entity_load('migration', 'd6_node_settings');
     $migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
     // Create a test node.
     $node = entity_create('node', array('type' => 'story', 'nid' => 1, 'vid' => 1, 'revision_log' => '', 'title' => $this->randomString()));
     $node->enforceIsNew();
     $node->save();
     $node = entity_create('node', array('type' => 'test_planet', 'nid' => 3, 'vid' => 4, 'revision_log' => '', 'title' => $this->randomString()));
     $node->enforceIsNew();
     $node->save();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig(array('filter', 'node'));
     $node_type = entity_create('node_type', array('type' => 'article', 'name' => 'Article'));
     $node_type->save();
     node_add_body_field($node_type);
 }
 /**
  * Create test content type.
  */
 protected static function createTestContentType()
 {
     $name = self::randomName(8);
     $type = (object) array('type' => $name, 'name' => $name, 'base' => 'node_content', 'description' => '', 'help' => '', 'title_label' => 'Title', 'body_label' => 'Body', 'has_title' => 1, 'has_body' => 1, 'orig_type' => '', 'old_type' => '', 'module' => 'node', 'custom' => 1, 'modified' => 1, 'locked' => 0);
     node_type_save($type);
     node_types_rebuild();
     node_add_body_field($type);
     self::$contentType = $type;
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $entity_ids = parent::import($row, $old_destination_id_values);
     if ($row->getDestinationProperty('create_body')) {
         $node_type = $this->storage->load(reset($entity_ids));
         node_add_body_field($node_type, $row->getDestinationProperty('create_body_label'));
     }
     return $entity_ids;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $node_type = entity_create('node_type', array('type' => 'story'));
     $node_type->save();
     node_add_body_field($node_type);
     $id_mappings = array('d6_node_type' => array(array(array('test_story'), array('story'))), 'd6_filter_format' => array(array(array(1), array('filtered_html')), array(array(2), array('full_html'))));
     $this->prepareIdMappings($id_mappings);
     // Create a test node.
     $node = entity_create('node', array('type' => 'story', 'nid' => 1, 'vid' => 1));
     $node->enforceIsNew();
     $node->save();
     // Load dumps.
     $dumps = array($this->getDumpDirectory() . '/Drupal6Node.php', $this->getDumpDirectory() . '/Drupal6NodeType.php', $this->getDumpDirectory() . '/Drupal6FieldInstance.php');
     $this->loadDumps($dumps);
 }
示例#10
0
 public function setUp()
 {
     parent::setup();
     $this->installConfig(array('pathauto', 'taxonomy', 'system', 'node'));
     $this->installEntitySchema('user');
     $this->installEntitySchema('node');
     $this->installEntitySchema('taxonomy_term');
     $this->installSchema('node', array('node_access'));
     $this->installSchema('system', array('url_alias', 'sequences', 'router'));
     $type = NodeType::create(['type' => 'page']);
     $type->save();
     node_add_body_field($type);
     \Drupal::service('router.builder')->rebuild();
     $this->currentUser = entity_create('user', array('name' => $this->randomMachineName()));
     $this->currentUser->save();
 }
 /**
  * Tests node body field storage persistence even if there are no instances.
  */
 public function testFieldOverrides()
 {
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $this->assertTrue($field_storage, 'Node body field storage exists.');
     $type = NodeType::create(['name' => 'Ponies', 'type' => 'ponies']);
     $type->save();
     node_add_body_field($type);
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $this->assertTrue(count($field_storage->getBundles()) == 1, 'Node body field storage is being used on the new node type.');
     $field = FieldConfig::loadByName('node', 'ponies', 'body');
     $field->delete();
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $this->assertTrue(count($field_storage->getBundles()) == 0, 'Node body field storage exists after deleting the only instance of a field.');
     \Drupal::service('module_installer')->uninstall(array('node'));
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $this->assertFalse($field_storage, 'Node body field storage does not exist after uninstalling the Node module.');
 }
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installSchema('node', array('node_access'));
     $this->installSchema('file', array('file_usage'));
     $this->installConfig(['node']);
     // Add text formats.
     $filtered_html_format = entity_create('filter_format', array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array()));
     $filtered_html_format->save();
     // Set up text editor.
     $editor = entity_create('editor', array('format' => 'filtered_html', 'editor' => 'unicorn'));
     $editor->save();
     // Create a node type for testing.
     $type = entity_create('node_type', array('type' => 'page', 'name' => 'page'));
     $type->save();
     node_add_body_field($type);
 }
示例#13
0
 /**
  * {@inheritdoc}
  */
 public function setUp($processor = NULL)
 {
     parent::setUp('rendered_item');
     // Load configuration and needed schemas. (The necessary schemas for using
     // nodes are already installed by the parent method.)
     $this->installConfig(array('system', 'filter', 'node', 'comment'));
     $this->installSchema('system', array('router'));
     \Drupal::service('router.builder')->rebuild();
     // Create a node type for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     node_add_body_field($type);
     // Create anonymous user role.
     $role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
     $role->save();
     // Insert the anonymous user into the database.
     $anonymous_user = User::create(array('uid' => 0, 'name' => ''));
     $anonymous_user->save();
     // Default node values for all nodes we create below.
     $node_data = array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => '', 'body' => array('value' => '', 'summary' => '', 'format' => 'plain_text'), 'uid' => $anonymous_user->id());
     // Create some test nodes with valid user on it for rendering a picture.
     $node_data['title'] = 'Title for node 1';
     $node_data['body']['value'] = 'value for node 1';
     $node_data['body']['summary'] = 'summary for node 1';
     $this->nodes[1] = Node::create($node_data);
     $this->nodes[1]->save();
     $node_data['title'] = 'Title for node 2';
     $node_data['body']['value'] = 'value for node 2';
     $node_data['body']['summary'] = 'summary for node 2';
     $this->nodes[2] = Node::create($node_data);
     $this->nodes[2]->save();
     // Set proper configuration for the tested processor.
     $config = $this->processor->getConfiguration();
     $config['view_mode'] = array('entity:node' => ['page' => 'full', 'article' => 'teaser'], 'entity:user' => 'compact', 'entity:comment' => 'teaser');
     $config['roles'] = array($role->id());
     $this->processor->setConfiguration($config);
     $this->index->save();
     $this->index->getDatasources();
     // Enable the classy theme as the tests rely on markup from that.
     \Drupal::service('theme_handler')->install(array('classy'));
     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('classy'));
 }
示例#14
0
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installSchema('node', array('node_access'));
     $this->installSchema('file', array('file_usage'));
     $this->installConfig(['node']);
     // Add text formats.
     $filtered_html_format = FilterFormat::create(array('format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array()));
     $filtered_html_format->save();
     // Set cardinality for body field.
     FieldStorageConfig::loadByName('node', 'body')->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)->save();
     // Set up text editor.
     $editor = Editor::create(['format' => 'filtered_html', 'editor' => 'unicorn']);
     $editor->save();
     // Create a node type for testing.
     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
     $type->save();
     node_add_body_field($type);
 }
示例#15
0
 /**
  * Sets up the test.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('file');
     $this->installSchema('system', ['key_value_expire']);
     $this->installSchema('node', array('node_access'));
     $this->installSchema('file', array('file_usage'));
     $this->installConfig(['node']);
     // Add text formats.
     $this->format = FilterFormat::create(['format' => 'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => ['filter_align' => ['status' => TRUE], 'filter_caption' => ['status' => TRUE]]]);
     $this->format->save();
     // Set up text editor.
     $editor = Editor::create(['format' => 'filtered_html', 'editor' => 'unicorn', 'image_upload' => ['max_size' => 100, 'scheme' => 'public', 'directory' => '', 'status' => TRUE]]);
     $editor->save();
     // Create a node type for testing.
     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
     $type->save();
     node_add_body_field($type);
     $this->installEntitySchema('user');
     \Drupal::service('router.builder')->rebuild();
 }
 /**
  * Creates a custom content type based on default settings.
  *
  * @param array $values
  *   An array of settings to change from the defaults.
  *   Example: 'type' => 'foo'.
  *
  * @return \Drupal\node\Entity\NodeType
  *   Created content type.
  */
 protected function createContentType(array $values = array())
 {
     // Find a non-existent random type name.
     if (!isset($values['type'])) {
         do {
             $id = strtolower($this->randomMachineName(8));
         } while (NodeType::load($id));
     } else {
         $id = $values['type'];
     }
     $values += array('type' => $id, 'name' => $id);
     $type = NodeType::create($values);
     $status = $type->save();
     node_add_body_field($type);
     if ($this instanceof \PHPUnit_Framework_TestCase) {
         $this->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', array('%type' => $type->id())))->__toString());
     } else {
         $this->assertEqual($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', array('%type' => $type->id())))->__toString());
     }
     return $type;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     entity_create('node_type', array('type' => 'test_planet'))->save();
     $node_type = entity_create('node_type', array('type' => 'story'));
     $node_type->save();
     node_add_body_field($node_type);
     $id_mappings = array('d6_node_type' => array(array(array('test_story'), array('story'))), 'd6_filter_format' => array(array(array(1), array('filtered_html')), array(array(2), array('full_html'))), 'd6_field_instance_widget_settings' => array(array(array('page', 'field_test'), array('node', 'page', 'default', 'test'))), 'd6_field_formatter_settings' => array(array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test'))));
     $this->prepareMigrations($id_mappings);
     $migration = entity_load('migration', 'd6_node_settings');
     $migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
     // Create a test node.
     $node = entity_create('node', array('type' => 'story', 'nid' => 1, 'vid' => 1));
     $node->enforceIsNew();
     $node->save();
     $node = entity_create('node', array('type' => 'test_planet', 'nid' => 3, 'vid' => 4));
     $node->enforceIsNew();
     $node->save();
     // Load dumps.
     $dumps = array($this->getDumpDirectory() . '/Drupal6Node.php', $this->getDumpDirectory() . '/Drupal6NodeType.php', $this->getDumpDirectory() . '/Drupal6FieldInstance.php');
     $this->loadDumps($dumps);
 }
示例#18
0
 /**
  * Checks whether emails get sent when a user creates a new article node.
  */
 function testMandrillEmail()
 {
     $this->installEntitySchema('node');
     $this->installEntitySchema('user');
     \Drupal::service('module_installer')->install(array('dblog', 'field'));
     // Use the state system collector mail backend.
     $config = \Drupal::configFactory()->getEditable('system.mail');
     $mail_plugins = array('default' => 'test_mail_collector');
     $config->set('interface', $mail_plugins)->save();
     // Reset the state variable that holds sent messages.
     \Drupal::state()->set('system.test_mail_collector', array());
     // Create a user account and set it as the current user.
     $user = entity_create('user', array('uid' => 1, 'mail' => '*****@*****.**'));
     $user->save();
     \Drupal::currentUser()->setAccount($user);
     // Set the site email address.
     \Drupal::configFactory()->getEditable('system.site')->set('mail', '*****@*****.**')->save();
     // Create the article content type and add the body field to it.
     $type = array('type' => 'article', 'name' => 'Article');
     $type = entity_create('node_type', $type);
     $type->save();
     $article = NodeType::load('article');
     node_add_body_field($article);
     // Create a random article node.
     $title = $this->randomMachineName();
     $values = array('uid' => $user->id(), 'title' => $title, 'body' => [['value' => 'test_body']], 'type' => 'article');
     $node = entity_create('node', $values);
     $node->save();
     // Check the latest captured emails.
     $captured_emails = \Drupal::state()->get('system.test_mail_collector');
     $sent_message = end($captured_emails);
     $this->assertTrue(!empty($sent_message));
     $this->assertEqual($sent_message['id'], 'd8mail_node_insert', 'Correct mail id.');
     $this->assertEqual($sent_message['to'], '*****@*****.**', 'Correct mail to.');
     $this->assertEqual($sent_message['from'], '*****@*****.**', 'Correct mail from.');
     $this->assertEqual($sent_message['subject'], sprintf("Node created: %s", $title), 'Correct mail subject.');
     $this->assertEqual($sent_message['body'], 'test_body' . PHP_EOL, 'Correct mail body.');
 }
示例#19
0
 /**
  * Tests token replacement for Views tokens supplied by the Node module.
  */
 public function testViewsTokenReplacement()
 {
     // Create the Article content type with a standard body field.
     /* @var $node_type \Drupal\node\NodeTypeInterface */
     $node_type = entity_create('node_type', ['type' => 'article', 'name' => 'Article']);
     $node_type->save();
     node_add_body_field($node_type);
     // Create a user and a node.
     $account = $this->createUser();
     $body = $this->randomMachineName(32);
     $summary = $this->randomMachineName(16);
     /** @var $node \Drupal\node\NodeInterface */
     $node = entity_create('node', ['type' => 'article', 'tnid' => 0, 'uid' => $account->id(), 'title' => 'Testing Views tokens', 'body' => [['value' => $body, 'summary' => $summary, 'format' => 'plain_text']]]);
     $node->save();
     $this->drupalGet('test_node_tokens');
     // Body: {{ body }}<br />
     $this->assertRaw("Body: <p>{$body}</p>");
     // Raw value: {{ body__value }}<br />
     $this->assertRaw("Raw value: {$body}");
     // Raw summary: {{ body__summary }}<br />
     $this->assertRaw("Raw summary: {$summary}");
     // Raw format: {{ body__format }}<br />
     $this->assertRaw("Raw format: plain_text");
 }
示例#20
0
 /**
  * Tests whether a field using a disabled format is rendered.
  */
 public function testDisabledFormat()
 {
     // Create a node type and add a standard body field.
     $node_type = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName())]);
     $node_type->save();
     node_add_body_field($node_type, $this->randomString());
     // Create a text format with a filter that returns a static string.
     $format = FilterFormat::create(['name' => $this->randomString(), 'format' => $format_id = Unicode::strtolower($this->randomMachineName())]);
     $format->setFilterConfig('filter_static_text', ['status' => TRUE]);
     $format->save();
     // Create a new node of the new node type.
     $node = Node::create(['type' => $node_type->id(), 'title' => $this->randomString()]);
     $body_value = $this->randomString();
     $node->body->value = $body_value;
     $node->body->format = $format_id;
     $node->save();
     // The format is used and we should see the static text instead of the body
     // value.
     $this->drupalGet($node->urlInfo());
     $this->assertText('filtered text');
     // Disable the format.
     $format->disable()->save();
     $this->drupalGet($node->urlInfo());
     // The format is not used anymore.
     $this->assertNoText('filtered text');
     // The text is not displayed unfiltered or escaped.
     $this->assertNoRaw($body_value);
     $this->assertNoEscaped($body_value);
     // Visit the dblog report page.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('admin/reports/dblog');
     // The correct message has been logged.
     $this->assertRaw(sprintf('Disabled text format: %s.', $format_id));
     // Programmatically change the text format to something random so we trigger
     // the missing text format message.
     $format_id = $this->randomMachineName();
     $node->body->format = $format_id;
     $node->save();
     $this->drupalGet($node->urlInfo());
     // The text is not displayed unfiltered or escaped.
     $this->assertNoRaw($body_value);
     $this->assertNoEscaped($body_value);
     // Visit the dblog report page.
     $this->drupalGet('admin/reports/dblog');
     // The missing text format message has been logged.
     $this->assertRaw(sprintf('Missing text format: %s.', $format_id));
 }
示例#21
0
 /**
  * Tests format disabling.
  */
 public function testDisableFormatWithEditor()
 {
     $formats = ['monocerus' => 'Monocerus', 'tattoo' => 'Tattoo'];
     // Install the node module.
     $this->container->get('module_installer')->install(['node']);
     $this->resetAll();
     // Create a new node type and attach the 'body' field to it.
     $node_type = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName())]);
     $node_type->save();
     node_add_body_field($node_type, $this->randomString());
     $permissions = ['administer filters', "edit any {$node_type->id()} content"];
     foreach ($formats as $format => $name) {
         // Create a format and add an editor to this format.
         $this->addEditorToNewFormat($format, $name);
         // Add permission for this format.
         $permissions[] = "use text format {$format}";
     }
     // Create a node having the body format value 'moncerus'.
     $node = Node::create(['type' => $node_type->id(), 'title' => $this->randomString()]);
     $node->body->value = $this->randomString(100);
     $node->body->format = 'monocerus';
     $node->save();
     // Log in as an user able to use both formats and edit nodes of created type.
     $account = $this->drupalCreateUser($permissions);
     $this->drupalLogin($account);
     // The node edit page header.
     $text = t('<em>Edit @type</em> @title', array('@type' => $node_type->label(), '@title' => $node->label()));
     // Go to node edit form.
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertRaw($text);
     // Disable the format assigned to the 'body' field of the node.
     FilterFormat::load('monocerus')->disable()->save();
     // Edit again the node.
     $this->drupalGet('node/' . $node->id() . '/edit');
     $this->assertRaw($text);
 }
示例#22
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $type = $this->entity;
     $type->setNewRevision($form_state->getValue(array('options', 'revision')));
     $type->set('type', trim($type->id()));
     $type->set('name', trim($type->label()));
     $status = $type->save();
     $t_args = array('%name' => $type->label());
     if ($status == SAVED_UPDATED) {
         drupal_set_message(t('The content type %name has been updated.', $t_args));
     } elseif ($status == SAVED_NEW) {
         node_add_body_field($type);
         drupal_set_message(t('The content type %name has been added.', $t_args));
         $context = array_merge($t_args, array('link' => $type->link($this->t('View'), 'collection')));
         $this->logger('node')->notice('Added content type %name.', $context);
     }
     $fields = $this->entityManager->getFieldDefinitions('node', $type->id());
     // Update title field definition.
     $title_field = $fields['title'];
     $title_label = $form_state->getValue('title_label');
     if ($title_field->getLabel() != $title_label) {
         $title_field->getConfig($type->id())->setLabel($title_label)->save();
     }
     // Update workflow options.
     // @todo Make it possible to get default values without an entity.
     //   https://www.drupal.org/node/2318187
     $node = $this->entityManager->getStorage('node')->create(array('type' => $type->id()));
     foreach (array('status', 'promote', 'sticky') as $field_name) {
         $value = (bool) $form_state->getValue(['options', $field_name]);
         if ($node->{$field_name}->value != $value) {
             $fields[$field_name]->getConfig($type->id())->setDefaultValue($value)->save();
         }
     }
     $this->entityManager->clearCachedFieldDefinitions();
     $form_state->setRedirectUrl($type->urlInfo('collection'));
 }
示例#23
0
<?php

$types = array(array('type' => 'page', 'name' => 'Basic page', 'base' => 'node_content', 'description' => 'Use <em>basic pages</em> for your static content, such as an \'About us\' page.', 'custom' => 1, 'modified' => 1, 'locked' => 0), array('type' => 'article', 'name' => 'Article', 'base' => 'node_content', 'description' => 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.', 'custom' => 1, 'modified' => 1, 'locked' => 0));
foreach ($types as $type) {
    $type = node_type_set_defaults($type);
    node_type_save($type);
    node_add_body_field($type);
}
 /**
  * Creates a custom content type based on default settings.
  *
  * @param $settings
  *   An array of settings to change from the defaults.
  *   Example: 'type' => 'foo'.
  * @return
  *   Created content type.
  */
 protected function backdropCreateContentType($settings = array())
 {
     // Find a non-existent random type name.
     do {
         $name = strtolower($this->randomName(8));
     } while (node_type_get_type($name));
     // Populate defaults array.
     $defaults = array('type' => $name, 'name' => $name, 'base' => 'node_content', 'description' => '', 'help' => '', 'title_label' => 'Title', 'body_label' => 'Body', 'has_title' => 1, 'has_body' => 1, 'is_new' => TRUE);
     // Imposed values for a custom type.
     $forced = array('orig_type' => '', 'old_type' => '', 'module' => 'node', 'custom' => 1, 'modified' => 1, 'locked' => 0);
     $type = $forced + $settings + $defaults;
     $type = (object) $type;
     $saved_type = node_type_save($type);
     menu_rebuild();
     node_add_body_field($type);
     $this->assertEqual($saved_type, SAVED_NEW, t('Created content type %type.', array('%type' => $type->type)));
     // Reset permissions so that permissions for this content type are available.
     $this->checkPermissions(array(), TRUE);
     return $type;
 }
示例#25
0
 /**
  * Tests deleting a bundle.
  */
 public function testDeleteBundle()
 {
     // Create a node bundle, display and form display object.
     $type = NodeType::create(array('type' => 'article'));
     $type->save();
     node_add_body_field($type);
     entity_get_display('node', 'article', 'default')->save();
     entity_get_form_display('node', 'article', 'default')->save();
     // Delete the bundle.
     $type->delete();
     $display = entity_load('entity_view_display', 'node.article.default');
     $this->assertFalse((bool) $display);
     $form_display = entity_load('entity_form_display', 'node.article.default');
     $this->assertFalse((bool) $form_display);
 }
示例#26
0
 /**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     if (!$update) {
         // Create a body if the create_body property is true and we're not in
         // the syncing process.
         if ($this->get('create_body') && !$this->isSyncing()) {
             $label = $this->get('create_body_label');
             node_add_body_field($this, $label);
         }
     } elseif ($this->getOriginalId() != $this->id()) {
         $update_count = node_type_update_nodes($this->getOriginalId(), $this->id());
         if ($update_count) {
             drupal_set_message(format_plural($update_count, 'Changed the content type of 1 post from %old-type to %type.', 'Changed the content type of @count posts from %old-type to %type.', array('%old-type' => $this->getOriginalId(), '%type' => $this->id())));
         }
     }
     if ($update) {
         // Clear the cached field definitions as some settings affect the field
         // definitions.
         $this->entityManager()->clearCachedFieldDefinitions();
     }
 }
示例#27
0
 /**
  * Adds availability reference field to a content type.
  *
  * @When /^I add the "(?<field_name>[^"]*)" availability reference field referencing to "(?<unit_types>[^"]*)" units in "(?<content_type>[^"]*)" content$/
  */
 public function iAddTheAvailabilityReferenceFieldReferencingToUnitsInPageContent($field_name, $unit_types, $content_type)
 {
     // Create the content type.
     // Make sure a testimonial content type doesn't already exist.
     if (!in_array($content_type, node_type_get_names())) {
         $type = array('type' => $content_type, 'name' => $content_type, 'base' => 'node_content', 'custom' => 1, 'modified' => 1, 'locked' => 0);
         $type = node_type_set_defaults($type);
         node_type_save($type);
         node_add_body_field($type);
         $this->content_types[] = $content_type;
     }
     // Create field ('rooms_booking_unit_options') if not exist.
     if (field_read_field($field_name) === FALSE) {
         $field = array('field_name' => $field_name, 'type' => 'rooms_availability_reference', 'cardinality' => -1, 'settings' => array('referenceable_unit_types' => drupal_map_assoc(explode(',', $unit_types))));
         field_create_field($field);
         $this->fields[] = $field_name;
     }
     if (field_read_instance('node', $field_name, $content_type) === FALSE) {
         // Create the instance on the bundle.
         $instance = array('field_name' => $field_name, 'entity_type' => 'node', 'label' => 'Availability reference', 'bundle' => $content_type, 'required' => FALSE, 'widget' => array('type' => 'rooms_availability_reference_autocomplete'));
         field_create_instance($instance);
     }
 }
示例#28
0
 /**
  * Tests renaming and deleting a bundle.
  */
 public function testRenameDeleteBundle()
 {
     // Create a node bundle, display and form display object.
     $type = NodeType::create(array('type' => 'article'));
     $type->save();
     node_add_body_field($type);
     entity_get_display('node', 'article', 'default')->save();
     entity_get_form_display('node', 'article', 'default')->save();
     // Rename the article bundle and assert the entity display is renamed.
     $type->old_type = 'article';
     $type->set('type', 'article_rename');
     $type->save();
     $old_display = entity_load('entity_view_display', 'node.article.default');
     $this->assertFalse((bool) $old_display);
     $old_form_display = entity_load('entity_form_display', 'node.article.default');
     $this->assertFalse((bool) $old_form_display);
     $new_display = entity_load('entity_view_display', 'node.article_rename.default');
     $this->assertEqual('article_rename', $new_display->getTargetBundle());
     $this->assertEqual('node.article_rename.default', $new_display->id());
     $new_form_display = entity_load('entity_form_display', 'node.article_rename.default');
     $this->assertEqual('article_rename', $new_form_display->getTargetBundle());
     $this->assertEqual('node.article_rename.default', $new_form_display->id());
     $expected_view_dependencies = array('config' => array('field.field.node.article_rename.body', 'node.type.article_rename'), 'module' => array('entity_test', 'text', 'user'));
     // Check that the display has dependencies on the bundle, fields and the
     // modules that provide the formatters.
     $dependencies = $new_display->calculateDependencies();
     $this->assertEqual($expected_view_dependencies, $dependencies);
     // Check that the form display has dependencies on the bundle, fields and
     // the modules that provide the formatters.
     $dependencies = $new_form_display->calculateDependencies();
     $expected_form_dependencies = array('config' => array('field.field.node.article_rename.body', 'node.type.article_rename'), 'module' => array('text'));
     $this->assertEqual($expected_form_dependencies, $dependencies);
     // Delete the bundle.
     $type->delete();
     $display = entity_load('entity_view_display', 'node.article_rename.default');
     $this->assertFalse((bool) $display);
     $form_display = entity_load('entity_form_display', 'node.article_rename.default');
     $this->assertFalse((bool) $form_display);
 }
示例#29
0
 /**
  * Creates a custom content type based on default settings.
  *
  * @param array $values
  *   An array of settings to change from the defaults.
  *   Example: 'type' => 'foo'.
  *
  * @return \Drupal\node\Entity\NodeType
  *   Created content type.
  */
 protected function drupalCreateContentType(array $values = array())
 {
     // Find a non-existent random type name.
     if (!isset($values['type'])) {
         do {
             $id = strtolower($this->randomMachineName(8));
         } while (NodeType::load($id));
     } else {
         $id = $values['type'];
     }
     $values += array('type' => $id, 'name' => $id);
     $type = entity_create('node_type', $values);
     $status = $type->save();
     node_add_body_field($type);
     \Drupal::service('router.builder')->rebuild();
     $this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created content type %type.', array('%type' => $type->id())));
     return $type;
 }
 /**
  * Creates a custom content type based on default settings.
  *
  * @param $settings
  *   An array of settings to change from the defaults.
  *   Example: 'type' => 'foo'.
  * @return
  *   Created content type.
  */
 protected function drupalCreateContentType($settings = array())
 {
     $name = strtolower($this->randomMachineName(8));
     $values = array('type' => $name, 'name' => $name, 'base' => 'node_content', 'title_label' => 'Title', 'body_label' => 'Body', 'has_title' => 1, 'has_body' => 1);
     $type = entity_create('node_type', $values);
     $saved = $type->save();
     node_add_body_field($type);
     $this->assertEqual($saved, SAVED_NEW, t('Created content type %type.', array('%type' => $type->id())));
     return $type;
 }