View source
<?php
namespace Drupal\Tests\cacheflush_cron\Functional;
use Drupal\Tests\BrowserTestBase;
class CacheFlushCronUI extends BrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'cacheflush_ui',
'cacheflush_cron',
];
public static $roles = [
'cacheflush create new',
'cacheflush administer',
'cacheflush view own',
'cacheflush edit own',
'cacheflush delete own',
];
public function setUp() {
parent::setUp();
$user = $this
->drupalCreateUser(self::$roles);
$this
->drupalLogin($user);
}
public function addForm() {
$this
->drupalGet('admin/structure/cacheflush/add');
$this
->assertResponse(200);
$this
->assertFieldByName('cron');
$this
->assertRaw(t('Enable cron job for this preset.'));
$this
->assertNoLink(t('EDIT'));
}
public function editForm() {
$this
->drupalGet('admin/structure/cacheflush/add');
$this
->assertResponse(200);
$this
->assertRaw(t('Enable cron job for this preset.'));
$data = [
'title' => 'NewEntityTitle',
'cron' => 1,
];
$this
->drupalPostForm('admin/structure/cacheflush/add', $data, t('Save'));
$entities = array_values(cacheflush_load_multiple_by_properties([
'title' => 'NewEntityTitle',
]));
$this
->assertEqual($entities[0]
->getTitle(), 'NewEntityTitle', 'Entity successfully created.');
$this
->drupalGet('cacheflush/' . $entities[0]
->id() . '/edit');
$this
->assertResponse(200);
$this
->assertFieldByName('cron', 1, 'Cron checkbox is checked.');
$this
->assertLink(t('Edit'));
$data['cron'] = 0;
$this
->drupalPostForm('cacheflush/' . $entities[0]
->id() . '/edit', $data, t('Save'));
$entities = array_values(cacheflush_load_multiple_by_properties([
'title' => 'NewEntityTitle',
]));
$this
->drupalGet('cacheflush/' . $entities[0]
->id() . '/edit');
$this
->assertResponse(200);
$this
->assertFieldByName('cron', 0, 'Cron checkbox is NOT checked.');
$data = [
'title' => 'NewEntityTitle2',
];
$this
->drupalPostForm('admin/structure/cacheflush/add', $data, t('Save'));
$entities = array_values(cacheflush_load_multiple_by_properties([
'title' => 'NewEntityTitle2',
]));
$this
->assertEqual($entities[0]
->getTitle(), 'NewEntityTitle2', 'Entity successfully created.');
$this
->drupalGet('cacheflush/' . $entities[0]
->id() . '/edit');
$this
->assertResponse(200);
$this
->assertFieldByName('cron', 0, 'Cron checkbox is NOT checked.');
$this
->assertNoLink('Edit');
}
}