acquia_vwo-1.0.x-dev/tests/src/Functional/AcquiaVwoContentTrait.php

tests/src/Functional/AcquiaVwoContentTrait.php
<?php

namespace Drupal\Tests\acquia_vwo\Functional;

use Drupal\taxonomy\Entity\Term;

// cspell:ignore Teste Pessoa Sessao Novo
/**
 * Acquia VWO content trait.
 */
trait AcquiaVwoContentTrait {

  /**
   * Helper to create content.
   */
  private function createNodes() {
    $storage = \Drupal::entityTypeManager()->getStorage('node');

    // Create terms.
    $terms = $this->createTerms();

    // Create node.
    $node = $storage->create(
      [
        'type' => 'vwo_article',
        'title' => 'Test article',
        'field_vwo_section' => [
          ['target_id' => $terms['section']->id()],
        ],
        'field_vwo_persona' => [
          ['target_id' => $terms['persona']->id()],
        ],
        'field_vwo_keywords' => [
          ['target_id' => $terms['keywords'][0]->id()],
          ['target_id' => $terms['keywords'][1]->id()],
        ],
        'path' => '/vwo_test',
        'status' => TRUE,
      ]
    );
    $node->save();

    // Add translation.
    $node->addTranslation('pt-br', [
      'title' => 'Teste',
      'path' => '/teste_vwo',
      'status' => TRUE,
    ])->save();
  }

  /**
   * Helper to create terms.
   *
   * @return array
   *   The list of terms created.
   */
  private function createTerms() {
    $term_section = Term::create([
      'name' => 'Section 1',
      'vid' => 'section',
    ]);
    $term_section->save();

    // Add translation.
    $term_section->addTranslation('pt-br', [
      'name' => 'Sessao 1',
    ])->save();

    $term_persona = Term::create([
      'name' => 'Persona 1',
      'vid' => 'persona',
    ]);
    $term_persona->save();

    // Add translation.
    $term_persona->addTranslation('pt-br', [
      'name' => 'Pessoa 1',
    ])->save();

    $term_keyword_1 = Term::create([
      'name' => 'Foo',
      'vid' => 'keywords',
    ]);
    $term_keyword_1->save();

    $term_keyword_2 = Term::create([
      'name' => 'Bar',
      'vid' => 'keywords',
    ]);
    $term_keyword_2->save();

    return [
      'section' => $term_section,
      'persona' => $term_persona,
      'keywords' => [$term_keyword_1, $term_keyword_2],
    ];
  }

  /**
   * Helper to update content.
   */
  public function updateContent() {
    $storage = \Drupal::entityTypeManager()->getStorage('node');
    $node = $storage->load(1);
    $node->title = 'Updated title';
    $node->save();
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc