You are here

public function CacheFlushUICRUD::crudTest in CacheFlush 8

Test CRUD.

1 call to CacheFlushUICRUD::crudTest()
CacheFlushUICRUD::testCrud in modules/cacheflush_ui/tests/src/Functional/CacheFlushUICRUD.php
Run CRUD test functions.

File

modules/cacheflush_ui/tests/src/Functional/CacheFlushUICRUD.php, line 136

Class

CacheFlushUICRUD
Test the UI CRUD.

Namespace

Drupal\Tests\cacheflush_ui\Functional

Code

public function crudTest() {

  // Test Entity create.
  $data = [
    'title' => 'NewEntityTitle',
    'vertical_tabs_core[bootstrap]' => 1,
    'vertical_tabs_core[config]' => 1,
  ];
  $this
    ->drupalPostForm('admin/structure/cacheflush/add', $data, t('Save'));
  $entities = array_values(cacheflush_load_multiple_by_properties([
    'title' => 'NewEntityTitle',
  ]));
  $this
    ->assertEqual($entities[0]
    ->getTitle(), 'NewEntityTitle', 'Entity successfully created.');

  // Test Entity update.
  $data2 = [
    'title' => 'UpdatedEntityTitle',
    'vertical_tabs_core[default]' => 1,
    'vertical_tabs_core[config]' => FALSE,
  ];
  $this
    ->drupalGet('cacheflush/' . $entities[0]
    ->id() . '/edit');
  $this
    ->assertFieldByName('vertical_tabs_core[bootstrap]', 'Entity 1: vertical_tabs_core[bootstrap] value appears correctly in the form.');
  $this
    ->assertFieldByName('vertical_tabs_core[config]', 'Entity 1: vertical_tabs_core[config] value appears correctly in the form.');
  $this
    ->assertFieldByName('vertical_tabs_core[default]', 'Entity 1: vertical_tabs_core[default] value appears correctly in the form.');
  $this
    ->drupalPostForm('cacheflush/' . $entities[0]
    ->id() . '/edit', $data2, t('Save'));
  $this->entityTypeManager
    ->getStorage('cacheflush')
    ->resetCache([
    $entities[0]
      ->id(),
  ]);
  $entities = array_values(cacheflush_load_multiple_by_properties([
    'title' => 'UpdatedEntityTitle',
  ]));
  $this
    ->assertEqual($entities[0]
    ->getTitle(), 'UpdatedEntityTitle', 'Entity successfully updated.');
  $this
    ->drupalGet('cacheflush/' . $entities[0]
    ->id() . '/edit');
  $this
    ->assertFieldByName('vertical_tabs_core[bootstrap]', 'Entity 1: vertical_tabs_core[bootstrap] value appears correctly in the form.');
  $this
    ->assertFieldByName('vertical_tabs_core[config]', 'Entity 1: vertical_tabs_core[config] value appears correctly in the form.');
  $this
    ->assertFieldByName('vertical_tabs_core[default]', 'Entity 1: vertical_tabs_core[default] value appears correctly in the form.');

  // Test delete page and delete.
  $this
    ->drupalGet('cacheflush/' . $entities[0]
    ->id() . '/delete');
  $this
    ->assertLink(t('Cancel'));
  $this
    ->assertFieldByName('op', t('Delete'));
  $this
    ->drupalPostForm(NULL, [], t('Delete'));
  $this
    ->drupalGet('cacheflush/' . $entities[0]
    ->id());
  $this
    ->assertResponse(404);
}