Commit d8389c2a authored by webchick's avatar webchick

Issue #2037569 by tstoeckler, ParisLaikos, wildflower_0002, pfrenssen,...

Issue #2037569 by tstoeckler, ParisLaikos, wildflower_0002, pfrenssen, tim.plunkett: Remove design_test module.
parent 4020361e
name: 'Design test'
type: module
description: 'Support module for design, markup, JavaScript, and CSS testing.'
package: Testing
version: VERSION
core: 8.x
hidden: true
<?php
/**
* @file
* Support module for design, markup, JavaScript, and CSS testing.
*/
/**
* Implements hook_menu().
*
* This implementation turns every subdirectory of this module into a category
* that is exposed as a menu link. Each subdirectory contains include files that
* consist of a callback function that maps to the semantics of the category.
* The following categories are supported:
* - form: Used for Form API element tests.
* - page: Used for theme function tests.
*
* For example, given an include file:
* @code
* ./page/list-operations.inc
* @endcode
* A menu router item with the path 'design_test/page/list-operations' will be
* auto-generated. Upon access, the function design_test_page_list_operations()
* will be called.
*
* The 'form' category behaves identically; e.g., for an include file
* './form/details.inc' a menu item for the path 'design_test/form/details' is
* created and the form constructor function design_test_form_details() will be
* called.
*
* Each resulting test page is enhanced with local actions that allow to quickly
* switch between enabled themes for verifying the expected output.
*/
function design_test_menu() {
// Turn each include file in the module directory into a local task.
$categories = array();
$module_path = drupal_get_path('module', 'design_test');
$tests = file_scan_directory($module_path, '/\.inc$/', array('key' => 'name', 'recurse' => TRUE));
foreach ($tests as $name => $file) {
// Build include file path and category.
$filepath = strtr($file->uri, array($module_path . '/' => ''));
list($category) = explode('/', $filepath, 2);
$categories[$category] = $category;
// Build router item path.
$path = preg_replace('@[^a-zA-Z0-9-]@', '-', $name);
// Build page callback function name.
$callback = "design_test_{$category}_" . strtr($path, '-', '_');
// Build router item callback.
if ($category == 'form') {
$page_callback = 'drupal_get_form';
}
else {
$page_callback = $callback;
}
$items["design_test/{$category}/{$path}"] = array(
'title' => drupal_ucfirst($name),
'theme callback' => 'design_test_menu_theme_callback',
'page callback' => $page_callback,
'page arguments' => array($callback),
'file' => $filepath,
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK | MENU_VISIBLE_IN_TREE,
);
}
$items['design_test'] = array(
'title' => 'Design test',
'route_name' => 'design.test',
);
$items['design_test/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
// Lastly, add the category containers.
foreach ($categories as $category) {
$items["design_test/{$category}"] = array(
'title' => drupal_ucfirst($category),
'route_name' => 'design.test',
'type' => MENU_LOCAL_TASK | MENU_VISIBLE_IN_TREE,
);
}
return $items;
}
/**
* Implements hook_menu_local_tasks_alter().
*/
function design_test_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($router_item['number_parts'] > 2 && strpos($root_path, 'design_test/') === 0) {
$actions = &$data['actions']['output'];
// Determine the currently selected theme, if any.
$selected_theme = drupal_container()->get('request')->query->get('theme');
$default_theme = \Drupal::config('system.theme')->get('default');
// Expand all enabled themes into action links.
$themes = list_themes();
foreach ($themes as $name => $theme) {
$action = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => $theme->info['name'],
'href' => $router_item['href'],
'localized_options' => array('html' => FALSE),
),
'#active' => $selected_theme == $name,
);
// Only add the theme-switcher query parameter for all non-default themes.
if ($name != $default_theme) {
$action['#link']['localized_options']['query']['theme'] = $name;
}
$actions[] = $action;
}
if ($themes > 1) {
$data['actions']['count']++;
}
}
}
/**
* Menu theme callback for design_test pages.
*
* Returns whichever theme name that has been passed via the 'theme' request
* query parameter. The returned value is validated by the menu system already.
*/
function design_test_menu_theme_callback() {
return drupal_container()->get('request')->query->get('theme');
}
design.test:
path: '/design_test/{category}'
defaults:
_content: '\Drupal\design_test\Controller\DesignTestController::categoryPage'
category: 'FALSE'
requirements:
_access: 'TRUE'
<?php
/**
* @file
* Details design test.
*/
/**
* Form constructor for testing theme_details().
*/
function design_test_form_details($form, &$form_state) {
$form['collapsible'] = array(
'#type' => 'details',
'#title' => 'Collapsible details',
'#description' => 'Details description',
'#collapsed' => FALSE,
'#states' => array(
'collapsed' => array(
':input[name="states-trigger"]' => array('checked' => TRUE),
),
),
);
$form['collapsed'] = array(
'#type' => 'details',
'#title' => 'Collapsed details',
'#description' => 'Details description',
'#collapsed' => TRUE,
);
$form['collapsed']['textfield'] = array(
'#type' => 'textfield',
'#title' => 'Textfield',
'#default_value' => '',
'#description' => 'Textfield description',
'#required' => TRUE,
);
$form['collapsed']['textarea'] = array(
'#type' => 'textarea',
'#title' => 'Textarea',
'#default_value' => '',
'#description' => 'Textarea description',
'#required' => TRUE,
);
$form['collapsed2'] = array(
'#type' => 'details',
'#title' => 'Details',
'#description' => 'Details description',
'#collapsed' => TRUE,
);
$form['collapsed2']['collapsible'] = array(
'#type' => 'details',
'#title' => 'Collapsible details',
'#description' => 'Details description',
'#collapsed' => FALSE,
);
$form['collapsed2']['collapsed'] = array(
'#type' => 'details',
'#title' => 'Collapsed details',
'#description' => 'Details description',
'#collapsed' => TRUE,
);
$form['collapsed2']['regular'] = array(
'#type' => 'details',
'#title' => 'Details',
'#description' => 'Details description',
);
$form['regular'] = array(
'#type' => 'details',
'#title' => 'Details',
'#description' => 'Details description',
);
#$form['#attributes'] = array('class' => array('search-form'));
$form['basic'] = array(
'#type' => 'details',
'#title' => 'Filter aliases',
'#attributes' => array('class' => array('container-inline')),
);
$form['basic']['filter'] = array(
'#type' => 'textfield',
'#title' => '',
'#default_value' => '',
'#maxlength' => 128,
'#size' => 25,
);
$form['basic']['actions'] = array(
'#type' => 'actions',
);
$form['basic']['actions']['submit'] = array(
'#type' => 'submit',
'#value' => 'Filter',
);
$form['basic']['actions']['reset'] = array(
'#type' => 'submit',
'#value' => 'Reset',
);
$form['body'] = array(
'#type' => 'text_format',
'#title' => 'Body',
);
// Vertical tabs.
// Replicate the entire form; some more black magic.
$subform = array_diff_key($form, array('group' => 0, 'tabs' => 0));
$form['group'] = array(
'#type' => 'vertical_tabs',
);
$form['tabs'][0] = array(
'#type' => 'details',
'#title' => 'Vertical tab 1',
'#description' => 'Description',
'#group' => 'group',
);
$form['tabs'][0] += $subform;
$form['tabs'][1] = array(
'#type' => 'details',
'#title' => 'Vertical tab 2',
'#description' => '<p>Description</p><p>Description</p>',
'#group' => 'group',
);
$form['tabs'][1] += $subform;
// In case you didn't know, vertical tabs are supported recursively.
$form['tabs'][0]['subgroup'] = array(
'#type' => 'vertical_tabs',
);
$form['subtabs'][0] = array(
'#type' => 'details',
'#title' => 'Vertical tab 1',
'#description' => 'Description',
'#group' => 'subgroup',
);
$form['subtabs'][0] += $subform;
$form['subtabs'][1] = array(
'#type' => 'details',
'#title' => 'Vertical tab 2',
'#description' => '<p>Description</p><p>Description</p>',
'#group' => 'subgroup',
);
$form['subtabs'][1] += $subform;
// #states supports:
// - a 'collapsed' state trigger
// - a 'collapsed' remote condition
$form['states-trigger'] = array(
'#type' => 'checkbox',
'#title' => 'Collapse first details',
'#weight' => -100,
);
$form['states-condition'] = array(
'#type' => 'checkbox',
'#title' => 'Required if second details are collapsed.',
'#states' => array(
'required' => array(
'details#edit-collapsed' => array('collapsed' => TRUE),
),
),
'#weight' => -100,
);
return $form;
}
<?php
/**
* @file
* Fieldset design test.
*/
/**
* Form constructor for testing theme_fieldset().
*/
function design_test_form_fieldset($form, &$form_state) {
$form['regular'] = array(
'#type' => 'fieldset',
'#title' => 'Fieldset',
'#description' => 'Fieldset description',
);
$form['collapsible'] = array(
'#type' => 'details',
'#title' => 'Collapsible details',
'#description' => 'Details description',
'#collapsed' => FALSE,
);
$form['collapsible']['fieldset'] = array(
'#type' => 'fieldset',
'#title' => 'Fieldset title',
'#description' => 'Fieldset description',
);
$form['collapsible']['fieldset']['textfield'] = array(
'#type' => 'textfield',
'#title' => 'Textfield',
'#description' => 'Textfield description',
'#required' => TRUE,
);
$form['collapsible']['fieldset']['textarea'] = array(
'#type' => 'textarea',
'#title' => 'Textarea',
'#description' => 'Textarea description',
);
$form['collapsed'] = $form['collapsible'];
$form['collapsed']['#title'] = 'Collapsed details';
$form['collapsed']['#collapsed'] = TRUE;
$form['nested'] = $form['regular'];
$form['nested']['#title'] = 'Parent fieldset';
$form['nested']['nested'] = $form['nested'];
$form['nested']['nested']['#title'] = 'Nested fieldset';
// Vertical tabs.
// Replicate the entire form; some more black magic.
$subform = array_diff_key($form, array('group' => 0, 'tabs' => 0));
$form['group'] = array(
'#type' => 'vertical_tabs',
);
$form['tabs'][0] = array(
'#type' => 'details',
'#title' => 'Vertical tab 1',
'#description' => 'Description',
'#group' => 'group',
);
$form['tabs'][0] += $subform;
$form['tabs'][1] = array(
'#type' => 'details',
'#title' => 'Vertical tab 2',
'#description' => '<p>Description</p><p>Description</p>',
'#group' => 'group',
);
$form['tabs'][1] += $subform;
// In case you didn't know, vertical tabs are supported recursively.
$form['tabs'][0]['subgroup'] = array(
'#type' => 'vertical_tabs',
);
$form['subtabs'][0] = array(
'#type' => 'details',
'#title' => 'Vertical tab 1',
'#description' => 'Description',
'#group' => 'subgroup',
);
$form['subtabs'][0] += $subform;
$form['subtabs'][1] = array(
'#type' => 'details',
'#title' => 'Vertical tab 2',
'#description' => '<p>Description</p><p>Description</p>',
'#group' => 'subgroup',
);
$form['subtabs'][1] += $subform;
return $form;
}
<?php
/**
* @file
* Contains \Drupal\design_test\Controller\DesignTestController.
*/
namespace Drupal\design_test\Controller;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
/**
* Controller routines for design_test routes.
*/
class DesignTestController implements ContainerInjectionInterface {
/**
* {@inheritdoc}
*/
public static function create() {
return new static();
}
/**
* Constructs a DesignTestController object.
*/
public function __construct() {
}
/**
* Menu for a category listing page.
*
* This is a specialized version of system_admin_menu_block_page(), which
* retrieves all direct child menu links of the current page, regardless of
* their type, skips default local tasks, and outputs them as a simple menu
* tree as the main page content.
*
* @param string $category
* The design test category being currently accessed.
* Maps to the subdirectory names of this module.
*
* @return array
* A render array containing a menu link tree.
*/
public function categoryPage($category) {
$link = menu_link_get_preferred();
$tree = menu_build_tree($link['menu_name'], array(
'expanded' => array($link['mlid']),
'min_depth' => $link['depth'] + 1,
'max_depth' => $link['depth'] + 2,
));
// Local tasks are hidden = -1, so normally not rendered in menu trees.
foreach ($tree as &$data) {
// Exclude default local tasks.
if (!($data['link']['type'] & MENU_LINKS_TO_PARENT)) {
$data['link']['hidden'] = 0;
}
}
return menu_tree_output($tree);
}
}
<?php
/**
* @file
* Tests Operations.
*/
/**
* Page callback for manual testing of operation links.
*/
function design_test_page_list_operations() {
$build = array(
'#theme' => 'table',
'#header' => array('Label', 'Created', 'Operations'),
'#rows' => array(),
);
// Add an item with a very long label, using common operations.
$build['#rows']['long']['label'] = l('An item with a very insanely long label, which offers quite a couple of common operations', 'item/long');
$build['#rows']['long']['created'] = format_interval(3200);
$build['#rows']['long']['operations'] = array(
'data' => array(
'#type' => 'operations',
'#subtype' => 'node',
'#links' => array(
'edit' => array(
'title' => 'edit',
'href' => 'item/long/edit',
),
'disable' => array(
'title' => 'disable',
'href' => 'item/long/disable',
),
'clone' => array(
'title' => 'clone',
'href' => 'item/long/clone',
),
'delete' => array(
'title' => 'delete',
'href' => 'item/long/delete',
),
),
),
);
// Add another item, using common operations.
$build['#rows']['another']['label'] = l('Another item, using common operations', 'item/another');
$build['#rows']['another']['created'] = format_interval(8600);
$build['#rows']['another']['operations'] = $build['#rows']['long']['operations'];
// Add an item with only one operation.
$build['#rows']['one']['label'] = l('An item with only one operation', 'item/one');
$build['#rows']['one']['created'] = format_interval(12400);
$build['#rows']['one']['operations'] = array(
'data' => array(
'#type' => 'operations',
'#subtype' => 'node',
'#links' => array(
'edit' => array(
'title' => 'edit',
'href' => 'item/long/edit',
),
),
),
);
// Add an item that can only be viewed.
$build['#rows']['view']['label'] = l('An item that can only be viewed', 'item/view');
$build['#rows']['view']['created'] = format_interval(12400);
$build['#rows']['view']['operations'] = array(
'data' => array(
'#type' => 'operations',
'#subtype' => 'node',
'#links' => array(),
),
);
// Add an item for which the default operation is denied.
$build['#rows']['denied']['label'] = l('An item for which the default operation is denied', 'item/denied');
$build['#rows']['denied']['created'] = format_interval(18600);
$build['#rows']['denied']['operations'] = $build['#rows']['long']['operations'];
unset($build['#rows']['denied']['operations']['data']['#links']['edit']);
return $build;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment