You are here

public function PropertiesAdministrationTestCase::testCreating in Dynamic properties 7

File

./properties.test, line 419
Contains tests for the properties.module

Class

PropertiesAdministrationTestCase
Tests for fields integration.

Code

public function testCreating() {
  $this
    ->loginAdmin();

  // Create 5 properties.
  $attributes = array();
  for ($i = 0; $i < 5; $i++) {
    $attributes[$i] = $this
      ->createAttribute();
  }

  // Create a category.
  $category = array(
    'name' => drupal_strtolower($this
      ->randomName(8)),
    'label' => $this
      ->randomName(20),
    'attributes[0][attribute]' => $attributes[3]->name,
  );

  // Add another attribute.
  $this
    ->drupalPost('admin/config/content/properties/categories/add', $category, t('Add another attribute'));

  // Assert that label has been inserted.
  $this
    ->assertText($attributes[3]->label);

  // And another one.
  $next_attribute = array(
    'attributes[1][attribute]' => $attributes[1]->name,
  );
  $this
    ->drupalPost(NULL, $next_attribute, t('Add another attribute'));

  // Assert that label has been inserted.
  $this
    ->assertText($attributes[1]->label);

  // Add a new attribute, try to submit.
  $new_attribute = array(
    'attributes[2][attribute]' => $name = drupal_strtolower($this
      ->randomName()),
  );
  $this
    ->drupalPost(NULL, $new_attribute, t('Save'));
  $this
    ->assertText(t('Attribute @name does not exist, a label must be provided to create it.', array(
    '@name' => $name,
  )));
  $label = array(
    'attributes[' . $name . '][label]' => $new_label = $this
      ->randomName(20),
  );
  $this
    ->drupalPost(NULL, $label, t('Save'));
  $this
    ->assertText(t('Category created.'));

  // Verify that new attribute has been created.
  $this
    ->drupalGet('admin/config/content/properties/attributes');
  $this
    ->assertText($new_label);
  $this
    ->assertText($name);
}