You are here

public function SearchApiEtTestCase::testIndex in Search API Entity Translation 7.2

Tests adding, updating and deleting multilingual Search API items.

File

tests/search_api_et.test, line 46
Tests for Search API Entity Translation.

Class

SearchApiEtTestCase
Tests adding, updating and deleting multilingual Search API items.

Code

public function testIndex() {

  // Create Basic page in English.
  $node_title = $this
    ->randomName();
  $node_body = $this
    ->randomName();
  $node = $this
    ->createPage($node_title, $node_body, 'en');
  $item_id = SearchApiEtHelper::buildItemId($node->nid, 'en');
  $this
    ->assertTrue($this
    ->itemIdExists($item_id));
  $this
    ->assertTrue($this
    ->itemIdExistsOnBackend($item_id));

  // Update without any changes.
  $this
    ->drupalPost('node/' . $node->nid . '/edit', array(), t('Save'));
  $this
    ->assertTrue($this
    ->itemIdNotExistsOnBackend($node->nid));

  // Delete the Basic page.
  $edit = array();
  $this
    ->drupalPost('node/' . $node->nid . '/delete', $edit, t('Delete'));
  $this
    ->assertTrue($this
    ->itemIdNotExists($item_id));
  $this
    ->assertTrue($this
    ->itemIdNotExistsOnBackend($item_id));

  // Create a second page in Language neutral.
  $node_title = $this
    ->randomName();
  $node_body = $this
    ->randomName();
  $edit = array(
    'title' => $node_title,
    "body[en][0][value]" => $node_body,
    'language' => LANGUAGE_NONE,
  );
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));
  $node2 = $this
    ->drupalGetNodeByTitle($node_title);
  $item_id = SearchApiEtHelper::buildItemId($node2->nid, LANGUAGE_NONE);
  $this
    ->assertTrue($this
    ->itemIdExists($item_id));
  $this
    ->assertTrue($this
    ->itemIdExistsOnBackend($item_id));

  // Delete the second page.
  $edit = array();
  $this
    ->drupalPost('node/' . $node2->nid . '/delete', $edit, t('Delete'));
  $this
    ->assertTrue($this
    ->itemIdNotExists($item_id));
  $this
    ->assertTrue($this
    ->itemIdNotExistsOnBackend($item_id));

  // Add Basic page with translations.
  $node = $this
    ->createPage($this
    ->randomName(), $this
    ->randomName(), 'en');
  $en_item_id = SearchApiEtHelper::buildItemId($node->nid, 'en');
  $this
    ->assertTrue($this
    ->itemIdExists($en_item_id));
  $this
    ->assertTrue($this
    ->itemIdExistsOnBackend($en_item_id));

  // Add a French translation.
  $this
    ->createTranslation($node, $node_title, $this
    ->randomName(), 'fr');
  $fr_item_id = SearchApiEtHelper::buildItemId($node->nid, 'fr');
  $this
    ->assertTrue($this
    ->itemIdExists($fr_item_id));
  $this
    ->assertTrue($this
    ->itemIdExistsOnBackend($fr_item_id));

  // Delete the French translation.
  $this
    ->deleteTranslation($node, 'fr');
  $this
    ->assertTrue($this
    ->itemIdExists($en_item_id));
  $this
    ->assertTrue($this
    ->itemIdExistsOnBackend($en_item_id));
  $this
    ->assertTrue($this
    ->itemIdNotExists($fr_item_id));
  $this
    ->assertTrue($this
    ->itemIdNotExistsOnBackend($fr_item_id));

  // Add Basic page and change its source language.
  $node = $this
    ->createPage($this
    ->randomName(), $this
    ->randomName(), 'en');
  $en_item_id = SearchApiEtHelper::buildItemId($node->nid, 'en');
  $this
    ->assertTrue($this
    ->itemIdExists($en_item_id));
  $this
    ->assertTrue($this
    ->itemIdExistsOnBackend($en_item_id));
  $this
    ->drupalPost('node/' . $node->nid . '/edit', array(
    'language' => 'fr',
  ), t('Save'));
  $fr_item_id = SearchApiEtHelper::buildItemId($node->nid, 'fr');
  $this
    ->assertTrue($this
    ->itemIdExists($fr_item_id));
  $this
    ->assertTrue($this
    ->itemIdExistsOnBackend($fr_item_id));
  $this
    ->assertTrue($this
    ->itemIdNotExists($en_item_id));
  $this
    ->assertTrue($this
    ->itemIdNotExistsOnBackend($en_item_id));
}