View source
<?php
namespace Drupal\relation\Tests;
use Drupal\Core\Database\Database;
use Drupal\relation\Entity\Relation;
use Drupal\relation\Entity\RelationType;
class RelationUITest extends RelationTestBase {
public function setUp() {
$this->sleep = TRUE;
parent::setUp();
$permissions = array(
'administer relation types',
'administer relations',
'administer relation fields',
'administer relation form display',
'administer relation display',
'delete any article content',
);
$this->web_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->web_user);
}
public function testRelationDelete() {
$relation = Relation::load($this->relation_id_directional);
$this
->drupalPostForm("relation/" . $relation
->id() . "/delete", array(), t('Delete'));
$arg = [
':relation_id' => $relation
->id(),
];
$this
->assertFalse((bool) Database::getConnection('default')
->queryRange('SELECT * FROM {relation} WHERE relation_id = :relation_id', 0, 1, $arg)
->fetchField(), 'Nothing in relation table after delete.');
$this
->assertFalse((bool) Database::getConnection('default')
->queryRange('SELECT * FROM {relation_revision} WHERE relation_id = :relation_id', 0, 1, $arg)
->fetchField(), 'Nothing in relation revision table after delete.');
$this
->drupalGet("admin/structure/relation/manage/{$this->relation_type_symmetric}/delete");
$num_relations = 1;
$this
->assertRaw(t('%type is used by @count relation. You can not remove this relation type until you have removed all %type relations.', [
'@count' => $num_relations,
'%type' => $this->relation_types['symmetric']['label'],
]), 'Correct number of relations found (1) for ' . $this->relation_types['symmetric']['label'] . ' relation type.');
}
public function testEntityDelete() {
$this
->assertTrue(count($this->relation_types));
$relation_exist = \Drupal::entityTypeManager()
->getStorage('relation')
->getQuery()
->range(0, 1)
->execute();
$this
->assertTrue($relation_exist);
$node = $this->node1
->id();
$this
->drupalPostForm("node/{$node}/delete", array(), t('Delete'));
$this
->assertText(t('The Article @label has been deleted.', [
'@label' => $this->node1
->label(),
]));
foreach ($this->relation_types as $relation_type) {
$relation_ids = \Drupal::entityQuery('relation')
->condition('relation_type', $relation_type['id'], '=')
->execute();
$type_manager = \Drupal::entityTypeManager()
->getStorage('relation');
$relations = $type_manager
->loadMultiple($relation_ids);
$type_manager
->delete($relations);
$relation_type_entity = RelationType::load($relation_type['id']);
$relation_type_entity
->delete();
$this
->assertFalse(RelationType::load($relation_type['id']));
}
$relation_type_exist = \Drupal::entityTypeManager()
->getStorage('relation_type')
->getQuery()
->count()
->execute();
$this
->assertFalse($relation_type_exist);
$relation_exist = \Drupal::entityTypeManager()
->getStorage('relation')
->getQuery()
->count()
->execute();
$this
->assertFalse($relation_exist);
$node = $this->node2
->id();
$this
->drupalPostForm("node/{$node}/delete", array(), t('Delete'));
$this
->assertText(t('The Article @label has been deleted.', [
'@label' => $this->node2
->label(),
]));
}
public function testRelationEndpointsField() {
}
}