You are here

protected function CommerceProductReferenceAutocompleteSynonymsWebTestCase::createTerms in Synonyms 7

Method to initiate all necessary terms for testing.

Overrides AbstractAutocompleteSynonymsWebTestCase::createTerms

File

synonyms_commerce/synonyms_commerce.test, line 62
Tests for the Synonyms Commerce module.

Class

CommerceProductReferenceAutocompleteSynonymsWebTestCase
Test synonyms autocomplete widget for commerce product reference field type.

Code

protected function createTerms() {
  $name = $this
    ->randomName();
  $product = (object) array(
    'type' => 'product',
    'title' => $name,
    'sku' => 'a' . drupal_strtolower($this
      ->randomName()),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['term1'] = $product;
  $name .= $this
    ->randomName();
  $product = (object) array(
    'type' => 'product',
    'title' => $name,
    'sku' => 'z' . drupal_strtolower($this
      ->randomName()),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['term1_longer_name'] = $product;
  $product = (object) array(
    'type' => 'product',
    'title' => $this
      ->randomName(),
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['no_synonyms'] = $product;
  $product = (object) array(
    'type' => 'product',
    'title' => $this
      ->randomName(),
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['enabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['one_synonym'] = $product;
  $product = (object) array(
    'type' => 'product',
    'title' => $this
      ->randomName(),
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['enabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['two_synonyms'] = $product;
  $name = $this
    ->randomName();
  $product = (object) array(
    'type' => 'product',
    'title' => $name,
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['enabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $name . $this
            ->randomName(),
        ),
      ),
    ),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['name_similar_synonym'] = $product;
  $name = 'similar_synonyms_';
  $product = (object) array(
    'type' => 'product',
    'title' => $this
      ->randomName(),
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['enabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $name . $this
            ->randomName(),
        ),
        array(
          'value' => $name . $this
            ->randomName(),
        ),
      ),
    ),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['similar_synonyms'] = $product;
  $name = 'one_term_name_another_synonym_';
  $product = (object) array(
    'type' => 'product',
    'title' => $name . $this
      ->randomName(),
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['name_another_synonym'] = $product;
  $product = (object) array(
    'type' => 'product',
    'title' => $this
      ->randomName(),
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['enabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $name . $this
            ->randomName(),
        ),
      ),
    ),
    $this->fields['disabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    ),
  );
  commerce_product_save($product);
  $this->terms['synonym_another_name'] = $product;
  $another_product_type = commerce_product_ui_product_type_new();
  $another_product_type['type'] = 'another_vocabulary';
  $another_product_type['name'] = $this
    ->randomName();
  commerce_product_ui_product_type_save($another_product_type);
  $product_similar_product = (object) array(
    'type' => $another_product_type['type'],
    'title' => $this
      ->entityLabel($this->terms['no_synonyms']),
    'sku' => drupal_strtolower($this
      ->randomName()),
  );
  commerce_product_save($product_similar_product);
  $product_similar_synonym = (object) array(
    'type' => $another_product_type['type'],
    'title' => $this->terms['one_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
    'sku' => drupal_strtolower($this
      ->randomName()),
  );
  commerce_product_save($product_similar_synonym);
  $synonym_similar_product = (object) array(
    'type' => $another_product_type['type'],
    'title' => $this
      ->randomName(),
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['enabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        $this
          ->entityLabel($this->terms['no_synonyms']),
      ),
    ),
  );
  commerce_product_save($synonym_similar_product);
  $synonym_similar_synonym = (object) array(
    'type' => $another_product_type['type'],
    'title' => $this
      ->randomName(),
    'sku' => drupal_strtolower($this
      ->randomName()),
    $this->fields['enabled']['field']['field_name'] => array(
      LANGUAGE_NONE => array(
        $this->terms['one_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
      ),
    ),
  );
  commerce_product_save($synonym_similar_synonym);
}