You are here

public function CacheFlushUICRUD::testCRUD in CacheFlush 7.3

Test CRUD.

File

modules/cacheflush_ui/cacheflush_ui.test, line 86
Contains test suite for cacheflush ui module.

Class

CacheFlushUICRUD
Test the UI CRUD.

Code

public function testCRUD() {

  // Test Entity create.
  $data = array(
    'title' => 'NewEntityTitle',
    'vertical_tabs_core[cache]' => 1,
    'vertical_tabs_core[cache_filter]' => 1,
  );
  $this
    ->drupalPost('admin/structure/cacheflush/add', $data, t('Save'));
  $entities = array_values(cacheflush_load_multiple(FALSE, array(
    'title' => 'NewEntityTitle',
  )));
  $this
    ->assertEqual($entities[0]->title, 'NewEntityTitle', 'Entity successfully created.');

  // Test Entity update.
  $data2 = array(
    'title' => 'UpdatedEntityTitle',
    'vertical_tabs_core[cache_path]' => 1,
    'vertical_tabs_core[cache_filter]' => FALSE,
  );
  $this
    ->drupalGet('cacheflush/' . $entities[0]->id . '/edit');
  $this
    ->assertFieldByName('vertical_tabs_core[cache]', 1, 'Entity 1: vertical_tabs_core[cache] value appears correctly in the form.');
  $this
    ->assertFieldByName('vertical_tabs_core[cache_filter]', 1, 'Entity 1: vertical_tabs_core[cache_filter] value appears correctly in the form.');
  $this
    ->assertFieldByName('vertical_tabs_core[cache_path]', 0, 'Entity 1: vertical_tabs_core[cache_path] value appears correctly in the form.');
  $this
    ->drupalPost('cacheflush/' . $entities[0]->id . '/edit', $data2, t('Update'));
  $entities = array_values(cacheflush_load_multiple(FALSE, array(
    'title' => 'UpdatedEntityTitle',
  ), TRUE));
  $this
    ->assertEqual($entities[0]->title, 'UpdatedEntityTitle', 'Entity successfully updated.');
  $this
    ->drupalGet('cacheflush/' . $entities[0]->id . '/edit');
  $this
    ->assertFieldByName('vertical_tabs_core[cache]', 1, 'Entity 1: vertical_tabs_core[cache] value appears correctly in the form.');
  $this
    ->assertFieldByName('vertical_tabs_core[cache_filter]', 0, 'Entity 1: vertical_tabs_core[cache_filter] value appears correctly in the form.');
  $this
    ->assertFieldByName('vertical_tabs_core[cache_path]', 1, 'Entity 1: vertical_tabs_core[cache_path] 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('Confirm'));
  $this
    ->drupalPost(NULL, array(), t('Confirm'));
  $this
    ->drupalGet('cacheflush/' . $entities[0]->id);
  $this
    ->assertResponse(404);
}