You are here

protected function FeedsParaMapperWebTestCase::isNestedCorrectly in Feeds Paragraphs 7

Checks if the Paragraphs fields are nested as expected.

1 call to FeedsParaMapperWebTestCase::isNestedCorrectly()
FeedsParaMapperWebTestCase::setUp in tests/FeedsParaMapperWebTestCase.test
Prepares the test environment.

File

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

Class

FeedsParaMapperWebTestCase
Test basic functionality via DrupalWebTestCase.

Code

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);
}