You are here

trait CatalogTestTrait in Ubercart 8.4

Utility functions to provide catalog taxonomy terms for test purposes.

This trait can only be used in classes which already use RandomGeneratorTrait. RandomGeneratorTrait is used in all the PHPUnit and Simpletest base classes.

Hierarchy

2 files declare their use of CatalogTestTrait
CatalogTestBase.php in uc_catalog/tests/src/Functional/CatalogTestBase.php
ProductKitTest.php in uc_product_kit/tests/src/Functional/ProductKitTest.php

File

uc_catalog/tests/src/Traits/CatalogTestTrait.php, line 15

Namespace

Drupal\Tests\uc_catalog\Traits
View source
trait CatalogTestTrait {

  /**
   * Returns a new term with random properties in the catalog vocabulary.
   *
   * @param array $values
   *   Array of values to override the default term values.
   */
  protected function createCatalogTerm(array $values = []) {
    $term = Term::create($values + [
      'name' => $this
        ->randomMachineName(),
      'description' => [
        'value' => $this
          ->randomMachineName(),
        'format' => 'plain_text',
      ],
      'vid' => 'catalog',
      'langcode' => Language::LANGCODE_NOT_SPECIFIED,
    ]);
    $term
      ->save();
    return $term;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CatalogTestTrait::createCatalogTerm protected function Returns a new term with random properties in the catalog vocabulary.