You are here

public function CacheFlushAdvancedTest::testAddInterface in CacheFlush 7.3

Test for add page.

File

modules/cacheflush_advanced/cacheflush_advanced.test, line 42
Contains test suite for cacheflush module.

Class

CacheFlushAdvancedTest
Defines a test for cacheflush module.

Code

public function testAddInterface() {

  // Check interface has all fields.
  $this
    ->drupalGet('admin/structure/cacheflush/add');
  $this
    ->assertRaw(t('Custom (advanced)'));
  $this
    ->assertFieldByName('vertical_tabs_advance[cacheflush_advanced_table][0][cid]');
  $this
    ->assertFieldByName('vertical_tabs_advance[cacheflush_advanced_table][0][table]');
  $this
    ->assertFieldByName('vertical_tabs_advance[cacheflush_advanced_table][0][wildcard]');
  $this
    ->assertFieldByName('advanced_remove_0');
  $this
    ->assertFieldByName('advance_add');

  // Test NO error generate if nothing completet on the advanced form.
  $this
    ->drupalPost(NULL, array(), t('Add another row'));
  $this
    ->assertRaw(t('Title field is required.'));
  $this
    ->assertNoRaw(t('The cache ID field is mandatory.'));
  $this
    ->assertNoRaw(t('The table field is mandatory.'));

  // Test if WILDCARD checked generate error for the table and cid field.
  $edit = array(
    'vertical_tabs_advance[cacheflush_advanced_table][0][wildcard]' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Add another row'));
  $this
    ->assertRaw(t('The cache ID field is mandatory.'));
  $this
    ->assertRaw(t('The table field is mandatory.'));

  // Test if WILDCARD checked and CID, error for table field.
  $edit = array(
    'vertical_tabs_advance[cacheflush_advanced_table][0][wildcard]' => TRUE,
    'vertical_tabs_advance[cacheflush_advanced_table][0][cid]' => 'test',
  );
  $this
    ->drupalPost(NULL, $edit, t('Add another row'));
  $this
    ->assertNoRaw(t('The cache ID field is mandatory.'));
  $this
    ->assertRaw(t('The table field is mandatory.'));

  // Test if WILDCARD checked and table, error for CID field.
  $edit = array(
    'vertical_tabs_advance[cacheflush_advanced_table][0][wildcard]' => TRUE,
    'vertical_tabs_advance[cacheflush_advanced_table][0][cid]' => '',
    'vertical_tabs_advance[cacheflush_advanced_table][0][table]' => 'cache',
  );
  $this
    ->drupalPost(NULL, $edit, t('Add another row'));
  $this
    ->assertRaw(t('The cache ID field is mandatory.'));
  $this
    ->assertNoRaw(t('The table field is mandatory.'));

  // Test if CID set, error for table field.
  $edit = array(
    'vertical_tabs_advance[cacheflush_advanced_table][0][wildcard]' => FALSE,
    'vertical_tabs_advance[cacheflush_advanced_table][0][cid]' => 'TEST',
    'vertical_tabs_advance[cacheflush_advanced_table][0][table]' => 0,
  );
  $this
    ->drupalPost(NULL, $edit, t('Add another row'));
  $this
    ->assertNoRaw(t('The cache ID field is mandatory.'));
  $this
    ->assertRaw(t('The table field is mandatory.'));

  // Test if table selected, error for CID field.
  $edit = array(
    'vertical_tabs_advance[cacheflush_advanced_table][0][cid]' => '',
    'vertical_tabs_advance[cacheflush_advanced_table][0][table]' => 'cache',
  );
  $this
    ->drupalPost(NULL, $edit, t('Add another row'));
  $this
    ->assertRaw(t('The cache ID field is mandatory.'));
  $this
    ->assertNoRaw(t('The table field is mandatory.'));

  // Test NO error if all is completeted.
  $edit = array(
    'vertical_tabs_advance[cacheflush_advanced_table][0][wildcard]' => TRUE,
    'vertical_tabs_advance[cacheflush_advanced_table][0][cid]' => 'TEST',
    'vertical_tabs_advance[cacheflush_advanced_table][0][table]' => 'cache',
  );
  $this
    ->drupalPost(NULL, $edit, t('Add another row'));
  $this
    ->assertNoRaw(t('The cache ID field is mandatory.'));
  $this
    ->assertNoRaw(t('The table field is mandatory.'));
}