You are here

public function RelationUITest::testRelationDelete in Relation 8

Same name and namespace in other branches
  1. 8.2 src/Tests/RelationUITest.php \Drupal\relation\Tests\RelationUITest::testRelationDelete()

Tests deletion of a relation.

File

src/Tests/RelationUITest.php, line 44

Class

RelationUITest
Relation UI.

Namespace

Drupal\relation\Tests

Code

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.');

  // @todo: test if field data was deleted.
  // CrudTest::testDeleteField has 'TODO: Also test deletion of the data
  // stored in the field ?'
  // Try deleting the content types.
  $this
    ->drupalGet("admin/structure/relation/manage/{$this->relation_type_symmetric}/delete");
  $num_relations = 1;

  // See RelationTypeDeleteConfirm buildForm.
  $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.');
}