You are here

public function BoxTests::testBoxesAPI in Boxes 7.2

Test the boxes API

File

./boxes.test, line 131
Tests for block.module.

Class

BoxTests

Code

public function testBoxesAPI() {
  $values = array(
    'delta' => 'test_boxes',
    'label' => t('Test boxes'),
    'title' => t('Test boxes'),
    'type' => $this->plugin_name,
    'view_mode' => 'default',
    'data' => array(
      'test_boolean' => FALSE,
      'test_string' => t('New String'),
      'test_array' => array(
        'test_array_1' => 'new_value',
      ),
    ),
  );
  $box = boxes_create($values);
  $this
    ->assertTrue(boxes_save($box), t('Box was saved'));
  $values['label'] = $values['title'] = t('Test boxes 2');
  $values['delta'] = 'test_boxes2';
  $box = boxes_create($values);
  $this
    ->assertTrue(boxes_save($box), t('Box was saved'));
  $boxes = array_values(boxes_load_multiple(FALSE, array(
    'type' => $this->plugin_name,
  )));
  $this
    ->assertEqual($boxes[0]->label, t('Test boxes'), 'Created and loaded boxes.');
  $this
    ->assertEqual($boxes[1]->label, t('Test boxes 2'), 'Created and loaded boxes.');

  // Delete the first boxes
  $delete_id = $boxes[0]->bid;
  boxes_delete($boxes[0]);
  $box = $boxes[1];

  // Try to load deleted boxes
  $delete_box = boxes_load($delete_id, TRUE);
  $this
    ->assertFalse($delete_box, t('Box Deleted'));

  // Load by delta
  $delta_box = boxes_load_delta('test_boxes2', TRUE);
  $this
    ->assertEqual($delta_box
    ->identifier(), $box
    ->identifier(), t('Box loaded by delta'));

  // Test devel pages
  if (module_exists('devel')) {
    $this
      ->drupalGet("block/{$box->identifier()}/devel");
    $this
      ->assertResponse(200, t('Devel load page is viewable'));
    $this
      ->assertText($box
      ->label(), t('Devel load page is viewable'));
    $this
      ->drupalGet("block/{$box->identifier()}/devel/render");
    $this
      ->assertResponse(200, t('Devel render page is viewable'));
    $this
      ->assertText($box
      ->label(), t('Devel render page is viewable'));
  }

  // Test a boxes with an invalid plugin
  $values['type'] = 'fake_plugin';
  $values['delta'] = 'fake_boxes_plugin';
  $box = boxes_create($values);
  $this
    ->assertTrue(boxes_save($box), t('Box with invalid type was saved'));
  $this
    ->assertTrue(boxes_load_delta('fake_boxes_plugin'), t('Box with an invalid plugin is loaded'));

  // Test a boxes with a plugin with an invalid class
  $values['delta'] = 'missing_class';
  $values['type'] = 'test_no_boxes';
  $box = boxes_create($values);
  $this
    ->assertTrue(boxes_save($box), t('Box with a plugin that has an invalid class is saved'));
  $this
    ->assertTrue(boxes_load_delta('missing_class'), t('Box with a plugin that has an invalid class is loaded'));
}