function SimplenewsSchedulerEditionDueTest::setUp in Simplenews Scheduler 2.0.x
Overrides DrupalWebTestCase::setUp().
Overrides SimplenewsSchedulerTestBase::setUp
File
- tests/
src/ Functional/ SimplenewsSchedulerEditionDueTest.php, line 15
Class
- SimplenewsSchedulerEditionDueTest
- Functional tests for simplenews_scheduler_get_newsletters_due().
Namespace
Drupal\Tests\simplenews_scheduler\FunctionalCode
function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser(array(
'access content',
'administer nodes',
'create simplenews_issue content',
'edit own simplenews_issue content',
'send newsletter',
'send scheduled newsletters',
'overview scheduled newsletters',
));
$this
->drupalLogin($admin_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 = Node::create(array(
'type' => 'simplenews_issue',
'title' => 'Parent',
'uid' => 1,
'status' => 1,
));
$node->simplenews_issue->target_id = 'default';
$node->simplenews_issue->handler = 'simplenews_all';
$node
->save();
// 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
->id(),
'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',
'title' => '[node:title] for [current-date:long]',
);
$record = (array) $node->simplenews_scheduler;
$query = \Drupal::database()
->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
->id();
}