You are here

function BoxesTestCase::testBoxes in Boxes 7

Same name and namespace in other branches
  1. 6 tests/boxes.test \BoxesTestCase::testBoxes()

Test creating and deleting a box.

File

tests/boxes.test, line 31

Class

BoxesTestCase

Code

function testBoxes() {

  // Add a new box by filling out the input form on the admin/build/block/add page.
  $box = array();
  $box['description'] = $this
    ->randomName(8);
  $box['title'] = $this
    ->randomName(8);
  $box['body[value]'] = $this
    ->randomName(32);
  $box['delta'] = strtolower($this
    ->randomName(16));
  $this
    ->drupalPost('admin/structure/block/box-add/simple', $box, t('Save'));

  // Confirm that the box has been created, and then query the created bid.
  $this
    ->assertText(t('@description has been created.', array(
    '@description' => $box['description'],
  )), t('Box successfully created.'));
  $delta = db_query("SELECT delta FROM {box} WHERE delta = :delta", array(
    'delta' => $box['delta'],
  ))
    ->fetchField();
  $this
    ->assertNotNull($delta, t('box found in database'));

  // Delete the created box & verify that it's been deleted and no longer appearing on the page.
  $this
    ->drupalPost('admin/structure/block/manage/boxes/' . $delta . '/delete/', array(), t('Delete'));

  // TODO check confirmation message ...of course we'd need to show one first.
  $delta = db_query("SELECT delta FROM {box} WHERE delta = :delta", array(
    'delta' => $box['delta'],
  ))
    ->fetchField();
  $this
    ->assertFalse($delta, t('box not found in database'));
}