diff --git a/core/modules/grid/grid.module b/core/modules/grid/grid.module index 4ec1e0b..71b36b4 100644 --- a/core/modules/grid/grid.module +++ b/core/modules/grid/grid.module @@ -51,7 +51,7 @@ function grid_menu() { 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); - $items['admin/structure/grids/grid/%grid/delete'] = array( + $items['admin/structure/grids/manage/%grid/delete'] = array( 'title' => 'Delete', 'page callback' => 'drupal_get_form', 'page arguments' => array('grid_confirm_delete', 4), diff --git a/core/modules/grid/lib/Drupal/grid/GridFormController.php b/core/modules/grid/lib/Drupal/grid/GridFormController.php index e8b4f9c..92eee32 100644 --- a/core/modules/grid/lib/Drupal/grid/GridFormController.php +++ b/core/modules/grid/lib/Drupal/grid/GridFormController.php @@ -58,7 +58,7 @@ public function form(array $form, array &$form_state, EntityInterface $grid) { '#type' => 'value', '#value' => $grid, ); - $form['options'] = $grid->getPlugin()->form($form, $form_state, $grid->options); + $form += $grid->getPlugin()->form($form, $form_state, $grid->options); return parent::form($form, $form_state, $grid); } @@ -67,7 +67,7 @@ public function form(array $form, array &$form_state, EntityInterface $grid) { * Overrides Drupal\Core\Entity\EntityFormController::validate(). */ public function validate(array $form, array &$form_state) { - $form_state['values']['grid']->getPlugin()->validate($form, $form_state['values']['options']); + $form_state['values']['grid']->getPlugin()->validate($form, $form_state); } /** diff --git a/core/modules/grid/lib/Drupal/grid/Plugin/grid/grid/EqualColumn.php b/core/modules/grid/lib/Drupal/grid/Plugin/grid/grid/EqualColumn.php index 94b631e..fb51c3d 100644 --- a/core/modules/grid/lib/Drupal/grid/Plugin/grid/grid/EqualColumn.php +++ b/core/modules/grid/lib/Drupal/grid/Plugin/grid/grid/EqualColumn.php @@ -135,20 +135,20 @@ public function form(array $full_form, array &$form_state, array $options) { /** * Form validation callback. */ - public function validate(array $form, array &$options_state) { - if ((intval($options_state['width']) != $options_state['width']) || $options_state['width'] == 0) { + public function validate(array $form, array &$form_state) { + if ((intval($form_state['values']['width']) != $form_state['values']['width']) || $form_state['values']['width'] == 0) { // Width should be a positive integer. form_set_error('columns', t('The width should be a positive number.')); } - if ((intval($options_state['columns']) != $options_state['columns']) || $options_state['columns'] == 0) { + if ((intval($form_state['values']['columns']) != $form_state['values']['columns']) || $form_state['values']['columns'] == 0) { // Columns should be a positive integer. form_set_error('columns', t('The number of columns should be a positive number.')); } - if (!is_numeric($options_state['padding_width'])) { + if (!is_numeric($form_state['values']['padding_width'])) { // Padding can be float as well (eg. 1.5 for 1.5% for fluid grids). - form_set_error('padding_width', t('The column padding should be a number. Enter 0 (zero) for no padding.' . $options_state['padding_width'])); + form_set_error('padding_width', t('The column padding should be a number. Enter 0 (zero) for no padding.' . $form_state['values']['padding_width'])); } - if (!is_numeric($options_state['gutter_width'])) { + if (!is_numeric($form_state['values']['gutter_width'])) { // Gutter can be float too (eg. 1.5 for 1.5% for fluid grids). form_set_error('gutter_width', t('The gutter width should be a number. Enter 0 (zero) for no gutter.')); } diff --git a/core/modules/grid/lib/Drupal/grid/Tests/GridTest.php b/core/modules/grid/lib/Drupal/grid/Tests/GridTest.php new file mode 100644 index 0000000..258bb53 --- /dev/null +++ b/core/modules/grid/lib/Drupal/grid/Tests/GridTest.php @@ -0,0 +1,134 @@ + 'Grid management', + 'description' => 'Tests grid management.', + 'group' => 'Grid', + ); + } + + /** + * Tests the default grids. + */ + function testDefaultGrids() { + // Create a new user, allow to manage grids. + $admin_user = $this->drupalCreateUser(array( + 'administer grids', + )); + $this->drupalLogin($admin_user); + + // Check that these grids show up on the user interface. + $test_grids = array( + 'ninesixty_12' => '960px wide, 12 column grid', + 'fluid_6' => 'Six column fluid', + 'fluid_12' => 'Twelve column fluid', + ); + + // Check if the visibility setting is available. + $this->drupalGet('admin/structure/grids'); + foreach($test_grids as $machine_name => $label) { + $this->assertText($machine_name); + $this->assertText($label); + } + } + + /** + * Tests editing a default grid. + */ + function testEditDefaultGrid() { + // Create a new user, allow to manage grids. + $admin_user = $this->drupalCreateUser(array( + 'administer grids', + )); + $this->drupalLogin($admin_user); + + $this->drupalGet('admin/structure/grids/manage/fluid_6/edit'); + $this->assertResponse(200); + $this->assertPattern('!disabled="disabled"(.+)id="edit-id"(.+)value="fluid_6"!', 'Existing grid machine name field is disabled.'); + + $edit = array('label' => 'Fluid: six column', 'padding_width' => '1'); + $this->drupalPost('admin/structure/grids/manage/fluid_6/edit', $edit, t('Save')); + $this->assertText('Fluid: six column'); + $this->assertNoText('Six column fluid'); + $this->assertRaw(t('Grid %label saved.', array('%label' => 'Fluid: six column'))); + } + + /** + * Tests deleting a default grid. + */ + function testDeleteDefaultGrid() { + // Create a new user, allow to manage grids. + $admin_user = $this->drupalCreateUser(array( + 'administer grids', + )); + $this->drupalLogin($admin_user); + + $this->drupalGet('admin/structure/grids/manage/fluid_12/delete'); + $this->assertResponse(200); + + $this->drupalPost('admin/structure/grids/manage/fluid_12/delete', array(), t('Delete')); + $this->assertRaw(t('Grid %label has been deleted.', array('%label' => 'Twelve column fluid'))); + $this->assertNoText('fluid_12'); + } + + /** + * Tests adding new grids and all actions on them. + */ + function testNewGrid() { + // Create a new user, allow to manage grids. + $admin_user = $this->drupalCreateUser(array( + 'administer grids', + )); + $this->drupalLogin($admin_user); + + $edit = array('label' => 'Three column fluid', 'id' => 'fluid_3', 'columns' => '3', 'units' => '%', 'padding_width' => '1.5', 'gutter_width' => '2'); + $this->drupalPost('admin/structure/grids/add', $edit, t('Save')); + $this->assertText('fluid_3'); + $this->assertRaw(t('Grid %label saved.', array('%label' => 'Three column fluid'))); + + $edit = array('label' => '320px wide, three column grid', 'id' => '320px_3col', 'columns' => '3', 'units' => 'px', 'width' => '320', 'padding_width' => '5', 'gutter_width' => '5'); + $this->drupalPost('admin/structure/grids/add', $edit, t('Save')); + $this->assertText('320px_3col'); + $this->assertRaw(t('Grid %label saved.', array('%label' => '320px wide, three column grid'))); + + $edit = array('label' => 'Fluid: three column'); + $this->drupalPost('admin/structure/grids/manage/fluid_3/edit', $edit, t('Save')); + $this->assertNoText('Three column fluid'); + $this->assertText('fluid_3'); + $this->assertRaw(t('Grid %label saved.', array('%label' => 'Fluid: three column'))); + + $edit = array('label' => 'Conflicting grid', 'id' => 'fluid_3'); + $this->drupalPost('admin/structure/grids/add', $edit, t('Save')); + $this->assertText(t('The machine-readable name is already in use. It must be unique.')); + + $this->drupalGet('admin/structure/grids/manage/fluid_3/edit'); + $this->assertPattern('!disabled="disabled"(.+)id="edit-id"(.+)value="fluid_3"!', 'Existing grid machine name field is disabled.'); + + $this->drupalPost('admin/structure/grids/manage/fluid_3/delete', array(), t('Delete')); + $this->assertRaw(t('Grid %label has been deleted.', array('%label' => 'Fluid: three column'))); + $this->assertNoText('fluid_3'); + } + +} diff --git a/core/modules/grid/tests/grid_test.info b/core/modules/grid/tests/grid_test.info new file mode 100644 index 0000000..ba4b138 --- /dev/null +++ b/core/modules/grid/tests/grid_test.info @@ -0,0 +1,6 @@ +name = Grid test +description = Helps with testing grids. +package = Testing +version = VERSION +core = 8.x +hidden = TRUE diff --git a/core/modules/grid/tests/grid_test.module b/core/modules/grid/tests/grid_test.module new file mode 100644 index 0000000..a65cd7e --- /dev/null +++ b/core/modules/grid/tests/grid_test.module @@ -0,0 +1,6 @@ +