View source
<?php
namespace Drupal\Tests\radioactivity\Unit;
use Drupal\Core\Site\Settings;
use Drupal\Tests\UnitTestCase;
use Drupal\radioactivity\Incident;
class IncidentTest extends UnitTestCase {
protected function setUp() : void {
parent::setUp();
new Settings([
'hash_salt' => 'liesjeleerdelotjelopen',
]);
}
public function testGetters() {
$incident = new Incident('field_name', 'entity_type', '99', 5.5, '1234567890');
$this
->assertEquals($incident
->getFieldName(), 'field_name');
$this
->assertEquals($incident
->getEntityTypeId(), 'entity_type');
$this
->assertEquals($incident
->getEntityId(), '99');
$this
->assertEquals($incident
->getEnergy(), 5.5);
}
public function testCreateFromPostData() {
$incident = Incident::createFromPostData([
'fn' => 'field_name',
'et' => 'entity_type',
'id' => '99',
'e' => 5.5,
'h' => '1234567890',
]);
$this
->assertEquals($incident
->getFieldName(), 'field_name');
$this
->assertEquals($incident
->getEntityTypeId(), 'entity_type');
$this
->assertEquals($incident
->getEntityId(), '99');
$this
->assertEquals($incident
->getEnergy(), 5.5);
}
public function testJson() {
$incident = new Incident('field_name', 'entity_type', '99', 5.5, '1234567890');
$this
->assertEquals($incident
->toJson(), '{"fn":"field_name","et":"entity_type","id":"99","e":5.5,"h":"5aa2ff01ac75da55751051a55021092768d079c5"}');
}
public function testValidHash() {
$incident = new Incident('field_name', 'entity_type', '99', 5.5, '1234567890');
$this
->assertFalse($incident
->isValid());
$incident = new Incident('field_name', 'entity_type', '99', 5.5, '5aa2ff01ac75da55751051a55021092768d079c5');
$this
->assertTrue($incident
->isValid());
}
}