first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,165 @@
<?php
class BoxesTestCase extends DrupalWebTestCase {
protected $profile = 'testing';
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Boxes functionality'),
'description' => t('Add and delete custom boxes.'),
'group' => t('Boxes'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp(array('comment', 'ctools', 'block', 'boxes'));
// Create and login user
$admin_user = $this->drupalCreateUser(array('administer blocks', 'administer boxes'));
$this->drupalLogin($admin_user);
}
/**
* Test creating and deleting a box.
*/
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'));
}
}
class BoxesAjaxTestCase extends DrupalWebTestCase {
/**
* Parse JSON that was generated by drupal_to_js
*
* Because of peculiarities of drupal_to_js we need to prepare our json
* for parsing.
*/
function parseJSON() {
// Step one; undo the "HTML escaping" that drupal does.
$json = str_replace(array('\x3c', '\x3e', '\x26'), array("<", ">", "&"), $this->content);
// Step two; handle our escaped single quotes with extreme care,
$json = str_replace(array("\'"), array("\x27"), $json);
// Step three; parse!
$json = json_decode($json);
// JSON_ERROR_NONE == 0 in PHP 5.3
$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;
}
/**
* Load a block via the context ajax callback and set the payload as the
* content for simpletest.
*/
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");
// Replace contents of the reponse with the decoded JSON
$this->content = $block;
}
else {
$this->fail('Failed to load block');
}
}
}
class BoxesBasicAjaxTestCase extends BoxesAjaxTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Boxes Ajax functionality'),
'description' => t('Add a custom boxes with AJAX.'),
'group' => t('Boxes'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('ctools', 'context', 'boxes');
// Create and login user
$admin_user = $this->drupalCreateUser(array('administer blocks', 'administer boxes'));
$this->drupalLogin($admin_user);
}
/**
* Test creating and deleting a box.
*/
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');
}
}

View File

@@ -0,0 +1,118 @@
<?php
class BoxesSpacesTestCase extends BoxesAjaxTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Boxes Spaces functionality'),
'description' => t('Add custom boxes in Spaces.'),
'group' => t('Boxes'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('ctools', 'boxes', 'features', 'purl', 'spaces', 'spaces_ui', 'spaces_user', 'taxonomy', 'spaces_taxonomy');
// Create and login user
$admin_user = $this->drupalCreateUser(array(
'administer blocks',
'administer boxes',
'administer spaces',
'administer site configuration',
'administer taxonomy',
));
$this->drupalLogin($admin_user);
}
function runTest($path) {
$this->ajaxLoadBoxesBlock('boxes_add__simple', $path);
$this->assertResponse('200', 'Response code 200');
$this->assertText(t('Add custom box'), 'Found box add form');
$edit = array(
'description' => $this->randomName(),
'title' => $this->randomName(),
'body' => $this->randomName(32),
);
$this->drupalPost(NULL, $edit, t('Save'));
$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, $path);
$this->assertResponse('200', 'Response code 200');
$this->assertText($edit['title'], 'Found box');
$this->ajaxLoadBoxesBlock($delta, 'node');
$this->assertNoText($edit['title'], "Block not available outside spaces.");
return $delta;
}
function testUserSpace() {
$delta = $this->runTest('user/3');
// Before this final check we make sure that user/%uid/features/override
// path is actually available. Some of our caches are over exuberant.
$this->drupalPost('admin/config/development/performance', array(), t('Clear cached data'));
$this->drupalGet('user/3/features/overrides');
$this->assertResponse('200', 'Response code 200');
$this->assertText($delta, 'Found overridden box: ' . $delta);
}
function testTermSpace() {
// Setup; set the purl type to path.
$edit = array('purl_types[path]' => 'path');
$this->drupalPost('admin/config/purl/types', $edit, t('Save configuration'));
// Setup; enable path prefixing for taxonomy spaces.
$edit = array('purl_method_spaces_taxonomy' => 'path');
$this->drupalPost('admin/config/purl', $edit, t('Save configuration'));
// Setup; create a vocabulary.
$edit = array(
'name' => $this->randomName(),
'module' => strtolower($this->randomName()),
);
$this->drupalPost('admin/structure/taxonomy/add/vocabulary', $edit, t('Save'));
// Setup; Enable this vocab for spaces_taxonomy.
$edit = array('spaces_taxonomy_vid' => '1');
$this->drupalPost('admin/structure/spaces/taxonomy', $edit, t('Save configuration'));
// Setup; Create our term space.
$edit = array(
'name' => $this->randomName(),
'purl[value]' => strtolower($this->randomName()),
);
$this->drupalPost('admin/structure/taxonomy/1/add/term', $edit, t('Save'));
// Testing!
$prefix = $edit['purl[value]'];
$this->drupalGet($prefix . '/node');
$this->assertResponse('200', 'Response code 200');
$delta = $this->runTest($prefix . '/node');
// Before this final check we make sure that user/%uid/features/override
// path is actually available. Some of our caches are over exuberant.
$this->drupalPost('admin/config/development/performance', array(), t('Clear cached data'));
$this->drupalGet('taxonomy/term/1/features/overrides');
$this->assertResponse('200', 'Response code 200');
$this->assertText($delta, 'Found overridden box: ' . $delta);
}
}