EquipmentFieldTest.php in farmOS 2.x
File
modules/asset/equipment/tests/src/Functional/EquipmentFieldTest.php
View source
<?php
namespace Drupal\Tests\farm_equipment\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\farm_test\Functional\FarmBrowserTestBase;
class EquipmentFieldTest extends FarmBrowserTestBase {
use StringTranslationTrait;
protected $user;
protected static $modules = [
'farm_entity',
'farm_equipment',
'farm_equipment_test',
];
protected function setUp() : void {
parent::setUp();
$this->user = $this
->createUser([
'administer assets',
'administer log',
]);
$this
->drupalLogin($this->user);
}
public function testEquipmentField() {
$entity_type_manager = $this->container
->get('entity_type.manager');
$asset_storage = $entity_type_manager
->getStorage('asset');
$log_storage = $entity_type_manager
->getStorage('log');
$asset = $asset_storage
->create([
'name' => $this
->randomMachineName(),
'type' => 'equipment',
]);
$asset
->save();
$this
->drupalGet('log/add/test');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldExists('equipment[0][target_id]');
$log = $log_storage
->create([
'type' => 'test',
]);
$log->equipment[] = [
'target_id' => $asset
->id(),
];
$log
->save();
$this
->drupalGet('log/' . $log
->id());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains("Equipment used");
}
}