You are here

class FeedsParaMapperWebTestCase in Feeds Paragraphs 7

Test basic functionality via DrupalWebTestCase.

Hierarchy

Expanded class hierarchy of FeedsParaMapperWebTestCase

File

tests/FeedsParaMapperWebTestCase.test, line 11
Common functionality for all Paragraphs Mapper tests.

View source
class FeedsParaMapperWebTestCase extends DrupalWebTestCase {
  protected $webUser;
  protected $profile = 'testing';
  protected $bundles;
  protected $contentType;
  protected $paragraphField;
  protected $importer;
  protected $multiValued = FALSE;
  protected $multiValuedParagraph = FALSE;
  protected $createdPlugins;
  protected $nested = FALSE;

  /**
   * Prepares the test environment.
   */
  public function setUp() {
    $args = func_get_args();
    if (isset($args[0])) {
      $this->multiValued = $args[0];
    }
    if (isset($args[1])) {
      $this->multiValuedParagraph = $args[1];
    }
    if (isset($args[2])) {
      $this->nested = $args[2];
    }
    $modules = array(
      'field',
      'field_ui',
      'image',
      'paragraphs',
      'feeds',
      'feeds_ui',
      'feeds_para_mapper',
    );
    $permissions = array(
      'bypass node access',
      'administer nodes',
      'administer feeds',
      'administer content types',
      'administer fields',
      'administer paragraphs bundles',
    );

    // If we are testing multi valued fields, load Feeds Tamper module:
    if ($this->multiValued || $this->multiValuedParagraph) {
      $modules[] = "feeds_tamper";
      $modules[] = "feeds_tamper_ui";
      $permissions[] = "administer feeds_tamper";
    }
    parent::setUp($modules);
    $this->webUser = $this
      ->drupalCreateUser($permissions);
    $this
      ->drupalLogin($this->webUser);

    // Create paragraphs bundles:
    $this
      ->createBundles();

    // Create a content type with a paragraph field:
    $this->contentType = "product";
    $this->paragraphField = "details";
    $last_key = count($this->bundles) - 1;
    $last_bundle = array(
      $this->bundles[$last_key]['name'],
    );
    $this
      ->createContentType($this->contentType, $this->paragraphField, $last_bundle);

    // Create importer for the content type:
    $this->importer = "product";
    $this
      ->addImporter($this->importer, $this->contentType);
    if ($this->nested) {
      $this
        ->isNestedCorrectly();
    }

    // Make sure that all assets files exist:
    $this
      ->assetsFilesExist();

    // Copy the image to the public path:
    $this
      ->copyFile('/tests/assets/image.png', 'public://image.png');
  }

  /**
   * Creates the needed Paragraphs bundles in a loop.
   *
   * 1- Create a bundle with a text field.
   * 2- Create another bundle with a paragraph field,
   * with the previous bundle as allowed.
   */
  protected function createBundles() {
    $counter = $this->nested ? 2 : 1;
    for ($i = 0; $i < $counter; $i++) {
      if ($i === 0) {
        $cardinality = $this->multiValued ? -1 : 1;
        $bundle = array(
          'name' => 'image_details_bundle',
          'fields' => array(
            array(
              'name' => 'description',
              'type' => "text",
              'widget' => 'text_textfield',
              'cardinality' => $cardinality,
              'mapping' => array(
                'text' => 'field_description',
              ),
              'mapping_multiple' => array(
                'text_multiple' => 'field_description',
              ),
            ),
            array(
              'name' => 'image',
              'type' => "image",
              'widget' => 'image_image',
              'cardinality' => $cardinality,
              'mapping' => array(
                'image_alt' => 'field_image:alt',
                'image_title' => 'field_image:title',
                'image_uri' => 'field_image:uri',
              ),
              'mapping_multiple' => array(
                'image_multi_alt' => 'field_image:alt',
                'image_multi_title' => 'field_image:title',
                'image_multi_uri' => 'field_image:uri',
              ),
            ),
          ),
        );
      }
      else {
        $isLast = $i + 1 === $counter;
        $cardinality = $this->multiValuedParagraph && $isLast ? -1 : 1;
        $bundle = array(
          'name' => 'image_bundle',
          'fields' => array(
            array(
              'name' => 'images',
              'type' => "paragraphs",
              'widget' => 'paragraphs_embed',
              'cardinality' => $cardinality,
              'allowed_bundles' => array(
                end($this->bundles)['name'],
              ),
            ),
          ),
        );
      }
      $this->bundles[] = $bundle;
      $this
        ->createBundle($bundle);
    }
  }

  /**
   * Creates a paragraph bundle.
   *
   * @param array $bundle
   *   Includes the bundle name and the field details.
   */
  protected function createBundle(array $bundle) {
    $this
      ->drupalGet('admin/structure/paragraphs/add');
    $edit = array(
      'name' => $bundle['name'],
      'bundle' => $bundle['name'],
    );
    $this
      ->drupalPost(NULL, $edit, t('Save Paragraph bundle'));
    $message = format_string("Created the paragraph bundle @name.", array(
      '@name' => $bundle['name'],
    ));
    $text = t("The paragraph bundle @name has been added.", array(
      '@name' => $bundle['name'],
    ));
    $this
      ->assertText($text, $message, 'Setup');

    // Add A field to the bundle:
    $bundle_name = $bundle['name'];
    $this
      ->drupalGet("admin/structure/paragraphs/{$bundle_name}/fields");
    $fields = $bundle['fields'];
    foreach ($fields as $field) {
      $allowed_bundles = array();
      if (isset($field['allowed_bundles'])) {
        $allowed_bundles = $field['allowed_bundles'];
      }
      $this
        ->createField($field['name'], $field['cardinality'], $field['type'], $field['widget'], $allowed_bundles);
    }
  }

  /**
   * Utility function to create a content type.
   *
   * @param string $name
   *   The content type name.
   * @param string $paragraph_field
   *   The paragraph field name to add to the content type.
   * @param array $allowed_bundles
   *   The allowed bundles for the paragraph field.
   */
  protected function createContentType($name, $paragraph_field, array $allowed_bundles) {
    $this
      ->drupalGet('admin/structure/types/add');
    $edit = array(
      'name' => $name,
      'type' => $name,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save and add fields'));
    $text = t('The content type @name has been added.', array(
      '@name' => $name,
    ));
    $this
      ->assertText($text, NULL, "Setup");
    $fields = array();
    $cardinality = $this->multiValuedParagraph ? -1 : 1;
    $fields[$paragraph_field] = array(
      'type' => "paragraphs",
      'widget' => 'paragraphs_embed',
      'cardinality' => $cardinality,
      'bundles' => $allowed_bundles,
    );
    foreach ($fields as $field_name => $details) {
      $this
        ->createField($field_name, $details['cardinality'], $details['type'], $details['widget'], $details['bundles']);
    }

    // Somehow clicking "save" isn't enough, and we have to do a
    // node_types_rebuild().
    node_types_rebuild();
    menu_rebuild();
    $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(
      ':type' => $name,
    ))
      ->fetchField();
    $this
      ->assertTrue($type_exists, "The new content type has been created in the database", "Setup");
  }

  /**
   * Utility function to create fields on a content type/paragraph bundle.
   *
   * @param string $field_name
   *   Name of the field, like field_something.
   * @param int $cardinality
   *   Cardinality.
   * @param string $type
   *   Field type.
   * @param string $widget
   *   Field widget.
   * @param array $bundles
   *   The allowed bundles if it's a paragraph field.
   */
  protected function createField($field_name, $cardinality, $type, $widget, array $bundles = array()) {

    // Add a singleton field_example_text field.
    $edit = array(
      'fields[_add_new_field][label]' => $field_name,
      'fields[_add_new_field][field_name]' => $field_name,
      'fields[_add_new_field][type]' => $type,
      'fields[_add_new_field][widget_type]' => $widget,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));

    // There are no settings for this, so just press the button.
    $this
      ->drupalPost(NULL, array(), t('Save field settings'));
    $edit = array(
      'field[cardinality]' => (string) $cardinality,
    );
    if (isset($bundles) && count($bundles)) {
      foreach ($bundles as $bundle) {
        $edit['instance[settings][allowed_bundles_table][' . $bundle . '][enabled]'] = "1";
      }
    }

    // Using all the default settings, so press the button.
    $this
      ->drupalPost(NULL, $edit, t('Save settings'));
    $message = format_string("Field @field added successfully", array(
      "@field" => $field_name,
    ));
    $this
      ->assertText(t('Saved @name configuration.', array(
      '@name' => $field_name,
    )), $message, "Setup");
  }

  /**
   * Creates a feed importer.
   *
   * @param string $name
   *   The importer name.
   * @param string $content_type
   *   The content type to attach to the importer.
   */
  protected function addImporter($name, $content_type) {
    $this
      ->drupalGet('admin/structure/feeds/create');
    $edit = array(
      'name' => $name,
      'id' => $name,
    );
    $this
      ->drupalPost(NULL, $edit, t('Create'));
    $message = format_string("Created importer with the name @name", array(
      '@name' => $name,
    ));
    $text = t("Your configuration has been created with default settings.");
    $this
      ->assertText($text, $message, "Setup");

    // Change the fetcher to the File upload fetcher (FeedsFileFetcher).
    $this
      ->drupalGet('admin/structure/feeds/' . $name . '/fetcher');
    $edit = array(
      'plugin_key' => 'FeedsFileFetcher',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $message = "Changed the fetcher to the file fetcher";
    $text = t("Changed fetcher plugin.");
    $this
      ->assertText($text, $message, "Setup");

    // Change the parser to CSV parser (FeedsCSVParser).
    $this
      ->drupalGet('admin/structure/feeds/' . $name . '/parser');
    $edit = array(
      'plugin_key' => 'FeedsCSVParser',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $message = "Changed the parser to the CSV Parser";
    $text = t("Changed parser plugin.");
    $this
      ->assertText($text, $message, "Setup");

    // Make sure the node processor is selected.
    $this
      ->drupalGet('admin/structure/feeds/' . $name . '/processor');
    $edit = array(
      'plugin_key' => 'FeedsNodeProcessor',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $message = "Changed the processor to Node Processor";
    $text = t("Changed processor plugin.");
    $this
      ->assertText($text, $message, "Setup");

    // Change the bundle to the $content_type.
    $this
      ->drupalGet('admin/structure/feeds/' . $name . '/settings/FeedsNodeProcessor');
    $edit = array(
      'bundle' => $content_type,
      'update_existing' => '2',
      'skip_hash_check' => '1',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $message = format_string("Selected @type content type as bundle for this importer", array(
      '@type' => $content_type,
    ));
    $text = t("Your changes have been saved.");
    $this
      ->assertText($text, $message, "Setup");
  }

  /**
   * Maps source fields to target fields.
   *
   * @param array $targets
   *   Contains the source and the target string names.
   */
  protected function map(array $targets) {
    $this
      ->drupalGet('admin/structure/feeds/' . $this->importer . '/mapping');
    $targets = array_unique($targets);
    $targets['id'] = "nid";
    $config_key = 0;
    $hasSettings = $this->multiValued && $this->multiValuedParagraph;
    foreach ($targets as $source => $target) {
      $edit = array(
        'source' => $source,
        'target' => $target,
      );
      $this
        ->drupalPost(NULL, $edit, t('Save'));
      $this
        ->assertText(t("Your changes have been saved."));
      $args = array(
        '@source' => $source,
        '@target' => $target,
      );
      $message = format_string("Mapped @source source to @target field", $args);
      $this
        ->assertText(t("Mapping has been added."), $message, 'Mapping');
      if ($target === 'nid') {

        // Set the target as unique:
        $edit = array(
          "config[{$config_key}][settings][unique]" => "1",
        );
      }
      elseif ($hasSettings) {
        $edit = array(
          "config[{$config_key}][settings][max_values]" => "2",
        );
      }
      if ($target === 'nid' || $hasSettings) {

        // Click the gear button so it shows the configuration form:
        $button_name = "mapping_settings_edit_" . $config_key;
        $this
          ->drupalPostAJAX(NULL, array(), $button_name);

        // Click update button.
        $button_name = "mapping_settings_update_" . $config_key;
        $this
          ->drupalPostAJAX(NULL, $edit, $button_name);

        // Save.
        $this
          ->drupalPost(NULL, array(), t('Save'));
      }
      $config_key++;
    }
  }

  /**
   * Starts importing.
   *
   * - Maps a paragraph field to a source.
   * - Imports node to a Paragraphs field.
   *
   * @param string $path
   *   The csv file path relative to the project root directory.
   * @param bool $updating
   *   Whether we are updating nodes or creating new ones.
   * @param bool $map
   *   Whether we should also map or just import.
   */
  protected function import($path = NULL, $updating = FALSE, $map = TRUE) {
    if ($map) {

      // Map the id field:
      $targets = array();
      $multi = $this->multiValued || $this->multiValuedParagraph;
      foreach ($this->bundles[0]['fields'] as $field) {
        if ($multi) {
          $targets = array_merge($targets, $field['mapping_multiple']);
        }
        else {
          $targets = array_merge($targets, $field['mapping']);
        }
      }
      $this
        ->map($targets);
      if ($multi) {
        foreach ($targets as $source => $target) {
          $this
            ->addTamperPlugins($source);
        }
      }
    }

    // Import content:
    $this
      ->drupalGet('import/' . $this->importer);
    if (!isset($path)) {
      $path = '/tests/assets/content.csv';
    }
    $file = $this
      ->getProjectPath() . $path;
    $edit = array(
      'files[feeds]' => $file,
    );
    $this
      ->drupalPost(NULL, $edit, "Import");
    $text = $updating ? 'Updated 1 node.' : 'Created 1 node.';
    $this
      ->assertText($text);
  }

  /**
   * Check that the top host field exists on the created node.
   */
  protected function topHostParagraphsFieldExists() {
    $node = node_load(1, NULL, TRUE);
    $host_field = "field_" . $this->paragraphField;
    $host_field_exists = isset($node->{$host_field});
    $message = "The host Paragraphs field exists on the node";
    $this
      ->assertTrue($host_field_exists, $message, "Importing");

    /*
        Check if the host Paragraphs field has the id
        of the created ParagraphsItemEntity.
    */
    $lang = $node->language;
    $id_exists = isset($node->{$host_field}[$lang][0]['value']);
    $message = "The host Paragraphs field has the id of the created ParagraphsItemEntity";
    $this
      ->assertTrue($id_exists, $message);
  }

  /**
   * Check whether the top host (node) has Paragraphs entity.
   */
  protected function topHostParagraphsEntityExists() {
    $item = $this
      ->getTopHostParagraphsEntities();
    $message = "The created paragraphs item entity found";
    $this
      ->assertTrue(count($item) > 0, $message, 'Importing');
  }

  /**
   * Gets the paragraphs items attached to the created node.
   *
   * @return array
   *   The attached items array.
   */
  protected function getTopHostParagraphsEntities() {
    $node = node_load(1);
    $lang = $node->language;
    $host_field = 'field_' . $this->paragraphField;
    $items = array();
    foreach ($node->{$host_field}[$lang] as $val) {
      $id = array(
        $val['value'],
      );
      $item = entity_load('paragraphs_item', $id, array(), TRUE);
      $item = reset($item);
      $items[] = $item;
    }
    return $items;
  }

  /**
   * Checks if the Paragraphs fields are nested as expected.
   */
  protected function isNestedCorrectly() {
    krsort($this->bundles);
    $this->bundles = array_values($this->bundles);
    foreach ($this->bundles as $key => $bundle) {
      foreach ($bundle['fields'] as $field) {
        $field = 'field_' . $field['name'];
        $instance = field_info_instance('paragraphs_item', $field, $bundle['name']);

        // If we have another bundle, it should have a Paragraphs field,
        // otherwise it should contain a text field:
        if (isset($this->bundles[$key + 1])) {
          $is_paragraph = $instance['widget']['module'] === "paragraphs";
          $message = format_string("The nested field @field is paragraph", array(
            "@field" => $field,
          ));
          $this
            ->assertTrue($is_paragraph, $message, 'Setup');
          if (isset($instance['settings']['allowed_bundles'])) {
            $allowed = $instance['settings']['allowed_bundles'];
            $next = $this->bundles[$key + 1];
            $has_next_bundle = $allowed[$next['name']] === $next['name'];
            $message = format_string("the @field has the next nested bundle as allowed", array(
              "@field" => $field,
            ));
            $this
              ->assertTrue($has_next_bundle, $message, "Setup");
          }
        }
        else {
          $expected = array(
            'text',
            'image',
          );
          $field_type = $instance['widget']['module'];
          $is_expected = in_array($field_type, $expected);
          $message = format_string("the field type @type is expected", array(
            "@type" => $field_type,
          ));
          $this
            ->assertTrue($is_expected, $message, "Setup");
        }
      }
    }
    krsort($this->bundles);
    $this->bundles = array_values($this->bundles);
  }

  /**
   * Get the paragraph field values.
   *
   * @param \ParagraphsItemEntity $paragraph
   *   The paragraph entity.
   * @param string $target
   *   The target field inside the paragraph entity.
   * @param array $values
   *   The previously collected values to append to.
   *
   * @return array
   *   array of the values.
   */
  protected function getValues(\ParagraphsItemEntity $paragraph, $target, array $values = array()) {
    $target_info = field_info_field($target);
    $node = node_load(1, NULL, TRUE);
    $lang = $node->language;
    if (isset($paragraph->{$target})) {
      if ($target_info['type'] === 'paragraphs' && isset($paragraph->{$target}[$lang])) {
        foreach ($paragraph->{$target}[$lang] as $item) {
          if (isset($item['value'])) {
            $id = array(
              $item['value'],
            );
            $entity = entity_load('paragraphs_item', $id, array(), TRUE);
            $values[] = reset($entity);
          }
        }
      }
      else {
        if (isset($paragraph->{$target}[$lang])) {
          foreach ($paragraph->{$target}[$lang] as $item) {
            if ($target_info['type'] === 'text') {
              $values[] = $item['value'];
            }
            else {
              $values[] = $item;
            }
          }
        }
      }
    }
    else {
      $keys = get_object_vars($paragraph);
      foreach ($keys as $key) {
        if (is_array($key) && isset($key[$lang]) && is_array($key[$lang])) {
          foreach ($key[$lang] as $item) {
            $item_id = (int) $item['value'];
            if ($item_id) {
              $en = entity_load('paragraphs_item', array(
                $item_id,
              ), array(), TRUE);
              $en = reset($en);
              if ($en) {
                $values = $this
                  ->getValues($en, $target, $values);
              }
            }
          }
        }
      }
    }
    return $values;
  }

  /**
   * Tests Multi-valued fields importing.
   *
   * @param array $expected_values
   *   The values that the entities should have.
   * @param bool $update
   *   Whether we are updating or creating new node.
   */
  protected function multiImport(array $expected_values, $update = FALSE) {
    $this
      ->import();
    $this
      ->topHostParagraphsFieldExists();
    $this
      ->topHostParagraphsEntityExists();
    $entities_count = 2;
    if ($update) {
      $entities_count = 3;
      $path = '/tests/assets/updated_content.csv';
      $this
        ->import($path, TRUE, FALSE);
    }
    $items = $this
      ->getTopHostParagraphsEntities();
    krsort($this->bundles);
    $this->bundles = array_values($this->bundles);

    // Check to see if the total of the created entities is correct:
    $paragraphs = NULL;
    if (count($this->bundles) > 1) {
      $parent = 'field_' . $this->bundles[0]['fields'][0]['name'];
      $paragraphs = $this
        ->getValues($items[0], $parent);
    }
    else {
      $paragraphs = $items;
    }
    $message = "The created Paragraphs entities are 2";
    $this
      ->assertEqual(count($paragraphs), $entities_count, $message, "Multi-valued Importing");

    // Test the entities values:
    $lastKey = count($this->bundles) - 1;
    foreach ($this->bundles[$lastKey]['fields'] as $field) {
      $machine_name = "field_" . $field['name'];
      $values = array();
      $values_count = array();
      $total_count = 0;
      foreach ($paragraphs as $paragraph) {
        $p_values = $this
          ->getValues($paragraph, $machine_name);
        $values_count[] = count($p_values);
        $total_count += count($p_values);
        $values = array_merge($values, $p_values);
      }

      // Test if each entity has total field values of 2:
      if ($total_count !== count($expected_values[$machine_name])) {
        for ($i = 0; $i < count($values_count); $i++) {
          $item_num = $i + 1;
          $message = format_string("Paragraph entity #@num has 2 values", array(
            "@num" => $item_num,
          ));
          $this
            ->assertEqual($values_count[$i], 2, $message, "Multi-valued Importing");
        }
      }
      $found_values = array();
      $expected_field_values = NULL;
      foreach ($expected_values as $values_field => $valuesArr) {
        if ($values_field === $machine_name) {
          $expected_field_values = $valuesArr;
          foreach ($valuesArr as $expected_value) {
            foreach ($values as $value) {
              if (is_array($expected_value)) {
                $total_found = 0;
                foreach ($expected_value as $subVal) {
                  if (in_array($subVal, $value)) {
                    $total_found++;
                  }
                }
                if (count($expected_value) === $total_found) {
                  $found_values[] = $expected_value;
                }
              }
              elseif ($value === $expected_value) {
                $found_values[] = $expected_value;
              }
            }
          }
        }
      }
      $message = "All field values are found";
      $this
        ->assertEqual(count($found_values), count($expected_field_values), $message);
    }
  }

  /**
   * Add the needed Tamper plugins (explode) in a loop.
   *
   * In order to import multiple values to a field, we need to use Tamper.
   *
   * @param string $source
   *   The source name.
   */
  protected function addTamperPlugins($source) {
    if (!isset($this->createdPlugins)) {
      $this->createdPlugins = array();
    }
    if ($this->multiValuedParagraph) {
      $settings = array(
        'settings[separator]' => '|',
      );
      $des = "Separate paragraphs";
      $plugin = $this
        ->addTamperPlugin($this->importer, $source, 'explode', $des, $settings);
      $this->createdPlugins[] = array(
        'source' => $source,
        'plugin' => $plugin,
      );
    }
    if ($this->multiValued) {
      $settings = array(
        'settings[separator]' => ',',
      );
      $des = "Separate values";
      $plugin = $this
        ->addTamperPlugin($this->importer, $source, 'explode', $des, $settings);
      $this->createdPlugins[] = array(
        'source' => $source,
        'plugin' => $plugin,
      );
    }
  }

  /**
   * Creates a Tamper plugin.
   *
   * @param string $importer
   *   The importer name.
   * @param string $source
   *   The source name.
   * @param string $plugin_id
   *   The plugin to add.
   * @param string $description
   *   The plugin description.
   * @param array $settings
   *   Configuration for the plugin (e.g The separator field value).
   *
   * @return string
   *   The plugin id.
   */
  protected function addTamperPlugin($importer, $source, $plugin_id, $description, array $settings = array()) {
    $url = "admin/structure/feeds/{$importer}/tamper/add/" . bin2hex($source);
    $edit = array(
      'plugin_id' => $plugin_id,
    );
    $this
      ->drupalPost($url, $edit, t('Choose'));
    $id = str_replace(' ', '_', $description);
    $id = strtolower($id);
    $edit = array(
      'plugin_id' => $plugin_id,
      'description' => $description,
      'id' => $id,
    );
    $edit = array_merge($edit, $settings);
    $this
      ->drupalPost(NULL, $edit, t("Add"));
    return $id;
  }

  /**
   * Checks if all assets files exist.
   */
  protected function assetsFilesExist() {
    $root = $this
      ->getProjectPath();
    $assets = array(
      'content.csv' => $root . '/tests/assets/content.csv',
      'updated_content.csv' => $root . '/tests/assets/updated_content.csv',
      'image.png' => $root . '/tests/assets/image.png',
    );
    foreach ($assets as $name => $path) {
      $exists = file_exists($path);
      $message = format_string("Asset file @name exists", array(
        "@name" => $name,
      ));
      $this
        ->assertTrue($exists, $message, "Setup");
    }
  }

  /**
   * Copies a file.
   *
   * @param string $source
   *   The path of the source file.
   * @param string $dest
   *   The path of the destination directory along with the file name.
   */
  public function copyFile($source, $dest) {
    $full_path = $this
      ->getProjectPath() . $source;
    $file = file_unmanaged_copy($full_path, $dest);
    $message = format_string("The file @source copied successfully", array(
      '@source' => $source,
    ));
    $this
      ->assertTrue(is_string($file), $message);
  }

  /**
   * Gets the project path.
   *
   * @return string
   *   The path.
   */
  public function getProjectPath() {
    $root = realpath(getcwd()) . '/';
    $path = $root . drupal_get_path('module', 'feeds_para_mapper');
    return $path;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
FeedsParaMapperWebTestCase::$bundles protected property
FeedsParaMapperWebTestCase::$contentType protected property
FeedsParaMapperWebTestCase::$createdPlugins protected property
FeedsParaMapperWebTestCase::$importer protected property
FeedsParaMapperWebTestCase::$multiValued protected property
FeedsParaMapperWebTestCase::$multiValuedParagraph protected property
FeedsParaMapperWebTestCase::$nested protected property
FeedsParaMapperWebTestCase::$paragraphField protected property
FeedsParaMapperWebTestCase::$profile protected property The profile to install as a basis for testing. Overrides DrupalWebTestCase::$profile
FeedsParaMapperWebTestCase::$webUser protected property
FeedsParaMapperWebTestCase::addImporter protected function Creates a feed importer.
FeedsParaMapperWebTestCase::addTamperPlugin protected function Creates a Tamper plugin.
FeedsParaMapperWebTestCase::addTamperPlugins protected function Add the needed Tamper plugins (explode) in a loop.
FeedsParaMapperWebTestCase::assetsFilesExist protected function Checks if all assets files exist.
FeedsParaMapperWebTestCase::copyFile public function Copies a file.
FeedsParaMapperWebTestCase::createBundle protected function Creates a paragraph bundle.
FeedsParaMapperWebTestCase::createBundles protected function Creates the needed Paragraphs bundles in a loop.
FeedsParaMapperWebTestCase::createContentType protected function Utility function to create a content type.
FeedsParaMapperWebTestCase::createField protected function Utility function to create fields on a content type/paragraph bundle.
FeedsParaMapperWebTestCase::getProjectPath public function Gets the project path.
FeedsParaMapperWebTestCase::getTopHostParagraphsEntities protected function Gets the paragraphs items attached to the created node.
FeedsParaMapperWebTestCase::getValues protected function Get the paragraph field values.
FeedsParaMapperWebTestCase::import protected function Starts importing.
FeedsParaMapperWebTestCase::isNestedCorrectly protected function Checks if the Paragraphs fields are nested as expected.
FeedsParaMapperWebTestCase::map protected function Maps source fields to target fields.
FeedsParaMapperWebTestCase::multiImport protected function Tests Multi-valued fields importing.
FeedsParaMapperWebTestCase::setUp public function Prepares the test environment. Overrides DrupalWebTestCase::setUp 5
FeedsParaMapperWebTestCase::topHostParagraphsEntityExists protected function Check whether the top host (node) has Paragraphs entity.
FeedsParaMapperWebTestCase::topHostParagraphsFieldExists protected function Check that the top host field exists on the created node.