Пример #1
0
 /**
  * {@inheritdoc}
  */
 function setUp()
 {
     parent::setUp();
     // Create Page content type.
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     }
     // Add two new languages.
     $language = new Language(array('id' => 'fr', 'name' => 'French'));
     language_save($language);
     $language = new Language(array('id' => 'es', 'name' => 'Spanish'));
     language_save($language);
     // Make the body field translatable. The title is already translatable by
     // definition.
     $field = FieldStorageConfig::loadByName('node', 'body');
     $field->translatable = TRUE;
     $field->save();
     // Set up node titles. They should not include the words "French",
     // "English", or "Spanish", as there is a language field in the view
     // that prints out those words.
     $this->node_titles = array('en' => array('First node en', 'Second node en'), 'es' => array('Primero nodo es', 'Segundo nodo es'), 'fr' => array('Premier nodule fr'));
     // Create nodes with translations.
     foreach ($this->node_titles['en'] as $index => $title) {
         $node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'en', 'type' => 'page'));
         foreach (array('es', 'fr') as $langcode) {
             if (isset($this->node_titles[$langcode][$index])) {
                 $translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode][$index]));
                 $translation->body->value = $this->randomName(32);
             }
         }
         $node->save();
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create Page content type.
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     }
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Make the body field translatable. The title is already translatable by
     // definition.
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $field_storage->translatable = TRUE;
     $field_storage->save();
     // Set up node titles. They should not include the words "French",
     // "English", or "Spanish", as there is a language field in the view
     // that prints out those words.
     $this->node_titles = array('es' => array('Primero nodo es', 'Segundo nodo es', 'Tercera nodo es'), 'en' => array('First node en', 'Second node en'), 'fr' => array('Premier nœud fr'));
     // Create nodes with translations.
     foreach ($this->node_titles['es'] as $index => $title) {
         $node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'es', 'type' => 'page', 'promote' => 1));
         foreach (array('en', 'fr') as $langcode) {
             if (isset($this->node_titles[$langcode][$index])) {
                 $translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode][$index]));
                 $translation->body->value = $this->randomMachineName(32);
             }
         }
         $node->save();
     }
     $user = $this->drupalCreateUser(array('access content overview', 'access content'));
     $this->drupalLogin($user);
 }
 function setUp()
 {
     parent::setUp();
     // Create Page content type.
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     }
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Make the body field translatable. The title is already translatable by
     // definition.
     $field_storage = FieldStorageConfig::loadByName('node', 'body');
     $field_storage->translatable = TRUE;
     $field_storage->save();
     // Set up node titles.
     $this->node_titles = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
     // Create node with translations.
     $node = $this->drupalCreateNode(array('title' => $this->node_titles['en'], 'langcode' => 'en', 'type' => 'page', 'body' => array(array('value' => $this->node_titles['en']))));
     foreach (array('es', 'fr') as $langcode) {
         $translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode]));
         $translation->body->value = $this->node_titles[$langcode];
     }
     $node->save();
 }
Пример #4
0
 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create two nodes.
     for ($i = 0; $i < 2; $i++) {
         $this->nodes[] = $this->drupalCreateNode(array('type' => 'article', 'body' => array(array('value' => $this->randomMachineName(42), 'format' => filter_default_format(), 'summary' => $this->randomMachineName()))));
     }
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create Article node type.
     $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     $this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('node');
     node_access_test_add_field(NodeType::load('article'));
     // After enabling a node access module, the access table has to be rebuild.
     node_access_rebuild();
     // Enable the private node feature of the node_access_test module.
     \Drupal::state()->set('node_access_test.private', TRUE);
 }
Пример #6
0
  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE) {
    parent::setUp($import_test_views);

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

    // Create some test nodes.
    $this->nodes = [];
    $langcodes = ['en', 'fr', 'it'];
    for ($i = 1; $i <= 5; $i++) {
      $langcode = $langcodes[($i - 1) % 3];
      $values = [
        'title' => $this->randomMachineName() . ' [' . $i . ':' . $langcode . ']',
        'langcode' => $langcode,
        'promote' => FALSE,
      ];
      $node = $this->drupalCreateNode($values);
      $this->pass(SafeMarkup::format('Node %title created with language %langcode.', ['%title' => $node->label(), '%langcode' => $node->language()->getId()]));
      $this->nodes[] = $node;
    }

    // Create translations for all languages for some nodes.
    for ($i = 0; $i < 2; $i++) {
      $node = $this->nodes[$i];
      foreach ($langcodes as $langcode) {
        if (!$node->hasTranslation($langcode)) {
          $title = $this->randomMachineName() . ' [' . $node->id() . ':' . $langcode . ']';
          $translation = $node->addTranslation($langcode, ['title' => $title, 'promote' => FALSE]);
          $this->pass(SafeMarkup::format('Translation %title created with language %langcode.', ['%title' => $translation->label(), '%langcode' => $translation->language()->getId()]));
        }
      }
      $node->save();
    }

    // Create a node with only one translation.
    $node = $this->nodes[2];
    $langcode = 'en';
    $title = $this->randomMachineName() . ' [' . $node->id() . ':' . $langcode . ']';
    $translation = $node->addTranslation($langcode, ['title' => $title]);
    $this->pass(SafeMarkup::format('Translation %title created with language %langcode.', ['%title' => $translation->label(), '%langcode' => $translation->language()->getId()]));
    $node->save();

    // Check that all created translations are selected by the test view.
    $view = Views::getView('test_node_bulk_form');
    $view->execute();
    $this->assertEqual(count($view->result), 10, 'All created translations are selected.');

    // Check the operations are accessible to the logged in user.
    $this->drupalLogin($this->drupalCreateUser(array('administer nodes', 'access content overview', 'bypass node access')));
    $this->drupalGet('test-node-bulk-form');
    $elements = $this->xpath('//select[@id="edit-action"]//option');
    $this->assertIdentical(count($elements), 8, 'All node operations are found.');
  }
 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(array('type' => 'article'));
     // Create comment field on article.
     $this->container->get('comment.manager')->addDefaultField('node', 'article');
     // Create two nodes, with 5 comments on all of them.
     for ($i = 0; $i < 2; $i++) {
         $this->nodes[] = $this->drupalCreateNode(array('type' => 'article', 'body' => array(array('value' => $this->randomMachineName(42), 'format' => filter_default_format(), 'summary' => $this->randomMachineName()))));
     }
     foreach ($this->nodes as $node) {
         for ($i = 0; $i < 5; $i++) {
             $this->comments[$node->id()][] = $this->drupalCreateComment(array('entity_id' => $node->id()));
         }
     }
 }
Пример #8
0
 function setUp()
 {
     parent::setUp();
     // Create Page content type.
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     }
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Set up node titles.
     $this->nodeTitles = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
     // Create node with translations.
     $node = $this->drupalCreateNode(['title' => $this->nodeTitles['en'], 'langcode' => 'en', 'type' => 'page', 'body' => [['value' => $this->nodeTitles['en']]]]);
     foreach (array('es', 'fr') as $langcode) {
         $translation = $node->addTranslation($langcode, ['title' => $this->nodeTitles[$langcode]]);
         $translation->body->value = $this->nodeTitles[$langcode];
     }
     $node->save();
 }