123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- class BoxesTestCase extends DrupalWebTestCase {
- protected $profile = 'testing';
-
- public static function getInfo() {
- return array(
- 'name' => t('Boxes functionality'),
- 'description' => t('Add and delete custom boxes.'),
- 'group' => t('Boxes'),
- );
- }
-
- function setUp() {
- parent::setUp(array('comment', 'ctools', 'block', 'boxes'));
-
- $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer boxes'));
- $this->drupalLogin($admin_user);
- }
-
- function testBoxes() {
-
- $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'));
-
- $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'));
-
- $this->drupalPost('admin/structure/block/manage/boxes/' . $delta . '/delete/', array(), t('Delete'));
-
- $delta = db_query("select delta from {box} where delta = :delta", array('delta' => $box['delta']))->fetchField();
- $this->assertFalse($delta, t('box not found in database'));
- }
- }
- class BoxesAjaxTestCase extends DrupalWebTestCase {
-
- function parseJSON() {
-
- $json = str_replace(array('\x3c', '\x3e', '\x26'), array("<", ">", "&"), $this->content);
-
- $json = str_replace(array("\'"), array("\x27"), $json);
-
- $json = json_decode($json);
-
- $error = function_exists('json_last_error')
- ? json_last_error()
- : $json == NULL? 1 : 0;
- if ($error === 0) {
- $this->pass("Parsed JSON response");
- }
- else {
- $this->fail("Failed to parse JSON response");
- }
- return $json;
- }
-
- function ajaxLoadBoxesBlock($delta, $path = 'node') {
- $this->drupalGet($path, array('query' => array('boxes_delta' => $delta)));
- $response = $this->parseJSON();
- $block = NULL;
- foreach ($response as $command) {
- if (($command->command == 'insert') && ($command->method == 'replaceWith')) {
- $block = $command->data;
- break;
- }
- }
- if ($block) {
- $this->pass("Loaded block");
-
- $this->content = $block;
- }
- else {
- $this->fail('Failed to load block');
- }
- }
- }
- class BoxesBasicAjaxTestCase extends BoxesAjaxTestCase {
-
- public static function getInfo() {
- return array(
- 'name' => t('Boxes Ajax functionality'),
- 'description' => t('Add a custom boxes with AJAX.'),
- 'group' => t('Boxes'),
- );
- }
-
- function setUp() {
- parent::setUp('ctools', 'context', 'boxes');
-
- $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer boxes'));
- $this->drupalLogin($admin_user);
- }
-
- function testAjaxBoxes() {
- $this->ajaxLoadBoxesBlock('boxes_add__simple');
- $this->assertText(t('Add custom box'), 'Found box add form');
- $edit = array(
- 'description' => $this->randomName(),
- 'title' => $this->randomName(),
- 'body[value]' => $this->randomName(32),
- );
- $this->drupalPost(NULL, $edit, t('Save'), array('query' => array('boxes_delta' => 'boxes_add__simple')));
- $response = $this->parseJSON();
- $delta = NULL;
- foreach ($response as $command) {
- if ($command->command == 'getBlock') {
- $delta = $command->delta;
- break;
- }
- }
- if (!$delta) {
- $this->fail('AJAX block submission failed');
- }
- $this->ajaxLoadBoxesBlock($delta);
- $this->assertText($edit['title'], 'Found box');
- }
- }
|