You are here

public function CommentAlterAdminTestCase::testNodeFieldInstanceSettings in Comment Alter 7

File

./comment_alter.test, line 298
Functional tests for the Comment Alter module.

Class

CommentAlterAdminTestCase
Functional tests for the admin UIs provided by Comment Alter.

Code

public function testNodeFieldInstanceSettings() {

  // Attach to the node (but without Comment Alter).
  $field_name = $this
    ->createField('text', 'text_textfield', array(
    'cardinality' => 1,
  ), array(), FALSE);
  $type_name = str_replace('_', '-', $this->content_type);
  $manage_field_path = "admin/structure/types/manage/{$type_name}/fields/{$field_name}";

  // Make sure nothing is alterable at the start.
  $alterable_fields = comment_alter_get_alterable_fields($this->content_type);
  $this
    ->assertEqual($alterable_fields, array());

  // Try form and make sure it works as expected.
  $this
    ->drupalGet($manage_field_path);
  $this
    ->assertFieldByName("instance[comment_alter]");
  $edit = array(
    'instance[comment_alter]' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));

  // Check our API to see that it's enabled now.
  drupal_static_reset('comment_alter_get_alterable_fields');
  $alterable_fields = comment_alter_get_alterable_fields($this->content_type);
  $this
    ->assertEqual($alterable_fields, array(
    $field_name,
  ));

  // Enable this field for to comment and ensure that the message is set
  // complaining about this.
  $this
    ->attachFieldToComment($field_name);
  $this
    ->drupalGet($manage_field_path);
  $this
    ->assertText(t('This field also exists on the comment. You must remove it from the comment in order to enable altering this field from comments.'));

  // Check our API to see that it's disabled now.
  drupal_static_reset('comment_alter_get_alterable_fields');
  $alterable_fields = comment_alter_get_alterable_fields($this->content_type);
  $this
    ->assertEqual($alterable_fields, array());
}