You are here

protected function FieldCollectionEntityTranslationTestCase::createPage in Field collection 7

Creates a basic page with a value in the field collection.

Parameters

int $num_values: The number of values to include in the field collection.

string $langcode: Language for the node.

1 call to FieldCollectionEntityTranslationTestCase::createPage()
FieldCollectionEntityTranslationTestCase::testEntityTranslation in ./field_collection.test
Ensures the right behaviour in all Entity Translation use cases.

File

./field_collection.test, line 889
Tests for field_collections.

Class

FieldCollectionEntityTranslationTestCase
Test using field collection with content that gets translated with Entity Translation.

Code

protected function createPage($num_values, $langcode = 'en') {

  // Check if num_values is greater than the field cardinality.
  if ($num_values > self::NUM_VALUES) {
    $num_values = self::NUM_VALUES;
  }
  $title = self::randomName();
  $this
    ->drupalGet('node/add/page');
  $edit = array();
  $edit['title'] = $title;
  for ($i = 0; $i < $num_values; $i++) {
    if ($i != 0) {
      $this
        ->drupalPost(NULL, array(), t('Add another item'));
    }
    $edit[$this->field_base . '[' . $i . ']' . $this->field_untrans_base] = self::UNTRANS_FIELD_EN . '_' . $i;
    $edit[$this->field_base . '[' . $i . ']' . $this->field_trans_base] = self::TRANS_FIELD_EN . '_' . $i;
  }
  $edit['language'] = $langcode;
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertRaw(t('Basic page %title has been created.', array(
    '%title' => $title,
  )), t('Basic page created.'));

  // Check to make sure the node was created.
  $node = $this
    ->drupalGetNodeByTitle($title);
  $this
    ->assertTrue($node, t('Node found in database.'));
  return $node;
}