You are here

function SimplenewsTestCase::setupSubscriptionBlock in Simplenews 7.2

Same name and namespace in other branches
  1. 6.2 tests/simplenews.test \SimplenewsTestCase::setupSubscriptionBlock()
  2. 7 tests/simplenews.test \SimplenewsTestCase::setupSubscriptionBlock()

Enable newsletter subscription block.

Parameters

int $newsletter_id: newsletter id

array $settings: ['message'] = Block message ['form'] = '1': Subscription form; '0': Link to form ['link to previous'] = {1, 0} Display link to previous issues ['previous issues'] = {1, 0} Display previous issues ['issue count'] = {1, 2, 3, ...}Number of issues to display ['rss feed'] = {1, 0} Display RSS-feed icon

4 calls to SimplenewsTestCase::setupSubscriptionBlock()
SimpleNewsAdministrationTestCase::testNewsletterSettings in tests/simplenews.test
Test various combinations of newsletter settings.
SimplenewsSubscribeTestCase::testSubscribeAnonymous in tests/simplenews.test
testSubscribeAnonymous
SimplenewsSubscribeTestCase::testSubscribeAnonymousSingle in tests/simplenews.test
Test anonymous subscription with single opt in.
SimplenewsSubscribeTestCase::testSubscribeAuthenticated in tests/simplenews.test
testSubscribeAuthenticated

File

tests/simplenews.test, line 110
Simplenews test functions.

Class

SimplenewsTestCase
@file Simplenews test functions.

Code

function setupSubscriptionBlock($newsletter_id, $settings = array()) {
  $bid = db_select('block')
    ->fields('block', array(
    'bid',
  ))
    ->condition('module', 'simplenews')
    ->condition('delta', $newsletter_id)
    ->execute();

  // Check to see if the box was created by checking that it's in the database..
  $this
    ->assertNotNull($bid, t('Block found in database'));

  // Set block parameters
  $edit = array();
  $edit['regions[bartik]'] = 'sidebar_first';
  if (isset($settings['message'])) {
    $edit['simplenews_block_m_' . $newsletter_id] = $settings['message'];
  }
  if (isset($settings['form'])) {
    $edit['simplenews_block_f_' . $newsletter_id] = $settings['form'];
  }
  if (isset($settings['link to previous'])) {
    $edit['simplenews_block_l_' . $newsletter_id] = $settings['link to previous'];
  }
  if (isset($settings['previous issues'])) {
    $edit['simplenews_block_i_status_' . $newsletter_id] = $settings['previous issues'];
  }
  if (isset($settings['issue count'])) {
    $edit['simplenews_block_i_' . $newsletter_id] = $settings['issue count'];

    // @todo check the count
  }
  if (isset($settings['rss feed'])) {
    $edit['simplenews_block_r_' . $newsletter_id] = $settings['rss feed'];
  }

  // Simplify confirmation form submission by hiding the subscribe block on
  // that page. Same for the newsletter/subscriptions page.
  $edit['pages'] = "newsletter/confirm/*\nnewsletter/subscriptions";
  $this
    ->drupalPost('admin/structure/block/manage/simplenews/' . $newsletter_id . '/configure', $edit, t('Save block'));
  $this
    ->assertText('The block configuration has been saved.', 'The newsletter block configuration has been saved.');
}