LogNamePatternTest.php in Log entity 2.x
File
tests/src/Functional/LogNamePatternTest.php
View source
<?php
namespace Drupal\Tests\log\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class LogNamePatternTest extends LogTestBase {
use StringTranslationTrait;
public function testCreateLogWithoutName() {
$edit = [
'status' => 'done',
];
$this
->drupalPostForm('log/add/name_pattern', $edit, $this
->t('Save'));
$result = $this->storage
->getQuery()
->range(0, 1)
->execute();
$log_id = reset($result);
$log = $this->storage
->load($log_id);
$this
->assertEquals($log
->label(), $log_id . ' done', 'Log name is the pattern and not the name.');
$this
->drupalGet($log
->toUrl('canonical'));
$this
->assertResponse(200);
$this
->assertText($log_id);
}
public function testCreateLogWithName() {
$name = $this
->randomMachineName();
$edit = [
'name[0][value]' => $name,
];
$this
->drupalPostForm('log/add/name_pattern', $edit, $this
->t('Save'));
$result = $this->storage
->getQuery()
->range(0, 1)
->execute();
$log_id = reset($result);
$log = $this->storage
->load($log_id);
$this
->assertEquals($log
->get('name')->value, $name, 'Log name is the pattern and not the name.');
$this
->drupalGet($log
->toUrl('canonical'));
$this
->assertResponse(200);
$this
->assertText($name);
}
public function testEditLog() {
$log = $this
->createLogEntity([
'type' => 'name_pattern',
]);
$log
->save();
$edit = [
'name[0][value]' => $this
->randomMachineName(),
];
$this
->drupalPostForm($log
->toUrl('edit-form'), $edit, $this
->t('Save'));
$this
->assertText($edit['name[0][value]']);
$edit = [
'name[0][value]' => '',
'status' => 'pending',
];
$this
->drupalPostForm($log
->toUrl('edit-form'), $edit, $this
->t('Save'));
$this
->assertText($log
->id() . ' pending');
$edit = [
'status' => 'done',
];
$this
->drupalPostForm($log
->toUrl('edit-form'), $edit, $this
->t('Save'));
$this
->assertText($log
->id() . ' done');
}
}