ZoneItemTest.php in Address 8
File
tests/src/Kernel/ZoneItemTest.php
View source
<?php
namespace Drupal\Tests\address\Kernel;
use CommerceGuys\Addressing\Zone\Zone;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
class ZoneItemTest extends EntityKernelTestBase {
public static $modules = [
'address',
];
protected $testEntity;
protected function setUp() : void {
parent::setUp();
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_zone',
'entity_type' => 'entity_test',
'type' => 'address_zone',
'cardinality' => 1,
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_name' => 'field_zone',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
]);
$field
->save();
$entity = EntityTest::create([
'name' => 'Test',
]);
$entity
->save();
$this->testEntity = $entity;
}
public function testZone() {
$zone = new Zone([
'id' => 'test',
'label' => 'Test',
'territories' => [
[
'country_code' => 'HU',
],
[
'country_code' => 'RS',
],
],
]);
$this->testEntity->field_zone = $zone;
$this->testEntity
->save();
$this->testEntity = $this
->reloadEntity($this->testEntity);
$this
->assertEquals($zone, $this->testEntity->field_zone->value);
}
}