PollExpirationTest.php in Poll 8
File
tests/src/Functional/PollExpirationTest.php
View source
<?php
namespace Drupal\Tests\poll\Functional;
use Drupal\poll\Entity\Poll;
class PollExpirationTest extends PollTestBase {
function testAutoExpire() {
$poll = $this->poll;
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('poll/' . $poll
->id() . '/edit');
$this
->assertField('runtime');
$elements = $this
->xpath('//select[@id="edit-runtime"]/option[@selected="selected"]');
$this
->assertEquals(0, $elements[0]
->getAttribute('value'), 'Poll expiration set to unlimited.');
$runtime = 604800;
$poll
->setRuntime($runtime);
$poll
->save();
$this
->drupalGet('poll/' . $poll
->id() . '/edit');
$elements = $this
->xpath('//select[@id="edit-runtime"]/option[@selected="selected"]');
$this
->assertEquals($runtime, $elements[0]
->getAttribute('value'), 'Poll expiration set to one week.');
\Drupal::service('cron')
->run();
$this
->assertTrue($poll
->isOpen(), 'Poll remains open after cron.');
$created = $poll
->getCreated();
$offset = $created - $runtime * 1.01;
$poll
->setCreated($offset);
$poll
->save();
\Drupal::service('cron')
->run();
$loaded_poll = Poll::load($poll
->id());
$this
->assertTrue($loaded_poll
->isClosed(), 'Poll has expired.');
}
}