function SimpleNewsSchedulerEditionDueTest::setUp in Simplenews Scheduler 7
Same name and namespace in other branches
- 6.2 tests/simplenews_scheduler.test \SimpleNewsSchedulerEditionDueTest::setUp()
Declares the module dependencies and create data for the test.
Overrides SimpleNewsSchedulerWebTestCase::setUp
File
- tests/
simplenews_scheduler.test, line 470 - Tests for Simplenews Scheduler.
Class
- SimpleNewsSchedulerEditionDueTest
- Unit testing for simplenews_scheduler_get_newsletters_due().
Code
function setUp() {
parent::setUp();
$this->privileged_user = $this
->drupalCreateUser(array(
'access content',
'administer nodes',
'create simplenews content',
'edit own simplenews content',
'send newsletter',
'send scheduled newsletters',
'overview scheduled newsletters',
));
$this
->drupalLogin($this->privileged_user);
// The start date of the edition. This is on 5 January so that we get some
// days in either month, and at at noon to keep things simple.
$this->edition_day = '05';
$start_date = new DateTime("2012-01-{$this->edition_day} 12:00:00");
// Create a parent newsletter node.
$node = (object) NULL;
$node->type = 'simplenews';
$node->title = 'Parent';
$node->uid = 1;
$node->status = 1;
$node->language = 'und';
// Safe to assume there is only one taxonomy term and it's the newsletter.
$node->field_simplenews_term['und'][0]['tid'] = 1;
// Workaround for http://drupal.org/node/1480258
$node->nid = NULL;
node_save($node);
// Grumble grumble there's no node saving API in our module!
// @see http://drupal.org/node/1480328 to clean this up.
$node->simplenews_scheduler = (object) array(
'nid' => $node->nid,
'last_run' => 0,
'activated' => '1',
'send_interval' => 'month',
'interval_frequency' => '1',
'start_date' => $start_date
->getTimestamp(),
'next_run' => $start_date
->getTimestamp(),
// Needs to be set manually when creating new records programmatically.
'stop_type' => '0',
'stop_date' => '0',
'stop_edition' => '0',
'php_eval' => '',
'title' => '[node:title] for [current-date:long]',
);
$record = (array) $node->simplenews_scheduler;
$query = db_merge('simplenews_scheduler');
$query
->key(array(
'nid' => $record['nid'],
))
->fields($record)
->execute();
// Store the node ID for the test to use.
$this->parent_nid = $node->nid;
}