DashboardTasksTest.php in farmOS 2.x
File
modules/core/ui/views/tests/src/Functional/DashboardTasksTest.php
View source
<?php
namespace Drupal\Tests\farm_ui_views\Functional;
use Drupal\log\Entity\Log;
use Drupal\Tests\farm_test\Functional\FarmBrowserTestBase;
class DashboardTasksTest extends FarmBrowserTestBase {
protected $user;
protected $role;
protected $log;
protected static $modules = [
'farm_observation',
'farm_ui_dashboard',
'farm_ui_views',
];
protected function setUp() : void {
parent::setUp();
$this->user = $this
->createUser([
'access farm dashboard',
]);
$this
->drupalLogin($this->user);
$this->role = $this
->drupalCreateRole([
'access farm dashboard',
'view any log',
]);
$this->log = Log::create([
'name' => 'Planned log',
'type' => 'observation',
'status' => 'done',
'timestamp' => \Drupal::time()
->getCurrentTime() + 86400,
]);
$this->log
->save();
}
public function testUpcomingTasks() {
$this
->drupalGet('/dashboard');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains('Upcoming tasks');
$this->user
->addRole($this->role);
$this->user
->save();
$this
->drupalGet('/dashboard');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Upcoming tasks');
$this
->assertSession()
->pageTextContains('No logs found.');
$this->log->status = 'pending';
$this->log->timestamp = \Drupal::time()
->getCurrentTime() + 86400;
$this->log
->save();
$this
->drupalGet('/dashboard');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Upcoming tasks');
$this
->assertSession()
->pageTextContains($this->log
->label());
}
public function testLateTasks() {
$this
->drupalGet('/dashboard');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains('Late tasks');
$this->user
->addRole($this->role);
$this->user
->save();
$this
->drupalGet('/dashboard');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Late tasks');
$this
->assertSession()
->pageTextContains('No logs found.');
$this->log->status = 'pending';
$this->log->timestamp = \Drupal::time()
->getCurrentTime() - 86400;
$this->log
->save();
$this
->drupalGet('/dashboard');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Late tasks');
$this
->assertSession()
->pageTextContains($this->log
->label());
}
}