mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
84 lines
1.9 KiB
PHP
84 lines
1.9 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Drupal\Tests\farm_id_tag\Kernel;
|
||
|
|
||
|
use Drupal\asset\Entity\Asset;
|
||
|
use Drupal\KernelTests\KernelTestBase;
|
||
|
|
||
|
/**
|
||
|
* Test ID tag field.
|
||
|
*
|
||
|
* @group farm
|
||
|
*/
|
||
|
class IdTagTest extends KernelTestBase {
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
protected static $modules = [
|
||
|
'asset',
|
||
|
'farm_field',
|
||
|
'farm_id_tag',
|
||
|
'farm_id_tag_test',
|
||
|
'state_machine',
|
||
|
'user',
|
||
|
];
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
public function setUp(): void {
|
||
|
parent::setUp();
|
||
|
$this->installEntitySchema('asset');
|
||
|
$this->installConfig(['farm_id_tag', 'farm_id_tag_test']);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test ID tag fields.
|
||
|
*/
|
||
|
public function testIdTagField() {
|
||
|
|
||
|
// Test creating a new asset and saving ID tag information.
|
||
|
$asset = Asset::create([
|
||
|
'name' => $this->randomString(),
|
||
|
'type' => 'test',
|
||
|
'id_tag' => [
|
||
|
'id' => '123456',
|
||
|
'type' => 'other',
|
||
|
'location' => 'Frame',
|
||
|
],
|
||
|
]);
|
||
|
$violations = $asset->validate();
|
||
|
$this->assertEmpty($violations);
|
||
|
$asset->save();
|
||
|
|
||
|
// Confirm that the asset was created with expected ID tag values.
|
||
|
$assets = Asset::loadMultiple();
|
||
|
$this->assertCount(1, $assets);
|
||
|
$this->assertEquals('123456', $assets[1]->get('id_tag')->id);
|
||
|
$this->assertEquals('other', $assets[1]->get('id_tag')->type);
|
||
|
$this->assertEquals('Frame', $assets[1]->get('id_tag')->location);
|
||
|
|
||
|
// Confirm that all sub-fields are optional.
|
||
|
$asset = Asset::create([
|
||
|
'name' => $this->randomString(),
|
||
|
'type' => 'test',
|
||
|
'id_tag' => [],
|
||
|
]);
|
||
|
$violations = $asset->validate();
|
||
|
$this->assertEmpty($violations);
|
||
|
$asset = Asset::create([
|
||
|
'name' => $this->randomString(),
|
||
|
'type' => 'test',
|
||
|
'id_tag' => [
|
||
|
'id' => '',
|
||
|
'type' => '',
|
||
|
'location' => '',
|
||
|
],
|
||
|
]);
|
||
|
$violations = $asset->validate();
|
||
|
$this->assertEmpty($violations);
|
||
|
}
|
||
|
|
||
|
}
|