You are here

function NotificationsCustomTests::createCustomFields in Notifications 7

Same name and namespace in other branches
  1. 6.4 tests/notifications_custom.test \NotificationsCustomTests::createCustomFields()

Add fields to custom subscription

Fields are arrays with 'type' and 'value'. The value must be the one entered in the form (i.e. user name)

1 call to NotificationsCustomTests::createCustomFields()
NotificationsCustomTests::createCustomSubscription in tests/notifications_custom.test
Create custom subscription through admin form

File

tests/notifications_custom.test, line 101

Class

NotificationsCustomTests

Code

function createCustomFields($subscription, $fields) {
  $path = "admin/messaging/customsubs/csid/{$subscription->csid}/fields";
  $this
    ->drupalGet($path);
  $this
    ->assertText('Fields', 'The Fields page for this subscription type shows up.');
  $index = count($subscription->fields);
  $this
    ->drupalGet($path);

  // Note we are posting to NULL path, this is for multi-stage forms
  foreach ($fields as $field) {
    $edit = array(
      'fields[name][new]' => $field['type'],
    );
    $this
      ->drupalPost(NULL, $edit, t(t('Add new field')));
    $edit = array(
      "fields[edit][{$index}]" => $field['value'],
    );
    $index++;
  }
  $this
    ->drupalPost(NULL, $edit, t(t('Save fields')));
  $this
    ->assertText('The fields for this subscription have been updated.');

  // Reload subscription
  messaging_static_reset('notifications_custom_load');
  $saved = notifications_custom_load($subscription->csid);
  $this
    ->assertEqual(count($saved->fields), $index, "The right number of fields have been added for this subscription. ({$index})");
  return $subscription;
}