You are here

function SimplenewsTestCase::getRandomNewsletter in Simplenews 7

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

Select randomly one of the available newsletters.

Return value

newsletter tid.

7 calls to SimplenewsTestCase::getRandomNewsletter()
SimpleNewsAdministrationTestCase::testSubscriptionManagement in tests/simplenews.test
Test newsletter subscription management.
SimpleNewsI18nTestCase::testCategoryTranslation in tests/simplenews.test
SimpleNewsI18nTestCase::testContentTranslation in tests/simplenews.test
SimplenewsSendTestCase::testProgrammaticNewsletter in tests/simplenews.test
Creates and sends a node using the API.
SimplenewsSourceTestCase::testSendCaching in tests/simplenews.test
Test sending a newsletter to 100 recipients with caching enabled.

... See full list

File

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

Class

SimplenewsTestCase
@file Simplenews test functions.

Code

function getRandomNewsletter() {
  $vid = db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE machine_name = :name', array(
    ':name' => 'newsletter',
  ))
    ->fetchField();
  if ($taxonomies = taxonomy_get_tree($vid)) {
    $tids = array();
    foreach ($taxonomies as $newsletter) {
      $tids[] = $newsletter->tid;
    }
    $key = array_rand($tids);
    return $tids[$key];
  }
  return 0;
}