Comments

voleger created an issue. See original summary.

voleger’s picture

Assigned: voleger » Unassigned
Status: Needs work » Needs review
StatusFileSize
new595 bytes
andypost’s picture

Title: Fix Weight form element behavior » Fix Weight form element behavior [D7]
manuel garcia’s picture

Issue tags: +Needs tests

Thanks !

voleger’s picture

voleger’s picture

Addressed @alexpott suggestion from parent issue.

The last submitted patch, 5: form_system-fix_weight_form_element-2946801-05-7.x-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 5: form_system-fix_weight_form_element-2946801-05-7.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 6: form_system-fix_weight_form_element-2946801-06-7.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

voleger’s picture

Status: Needs work » Needs review
StatusFileSize
new1.51 KB
new853 bytes

Typo. This time the test should be green.

#5 comment has test only patch.

ToxaViking’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

mustanggb’s picture

Issue tags: +Drupal 7.60 target
joseph.olstad’s picture

Issue tags: -Drupal 7.60 target +Drupal 7.61 target

Bumping to 7.61, this didn't make it into 7.60

joseph.olstad’s picture

joseph.olstad’s picture

mustanggb’s picture

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

1) The patch looks good but we need to backport the D8 weight tests from here: / #565220: Fix Weight form element behavior
2) To increase our confidence in the test results for the above issue, these two should go in first so we can re-queue php 7.3 and php 5.3 tests.
#3047844: [Regression] Tests fail on PHP 5.3
#3025335: session_id() cannot be changed after session is started

For the fame and glory, anyone want to backport the tests from here?

voleger’s picture

Status: Needs work » Needs review
+++ b/modules/simpletest/tests/form.test
@@ -588,6 +588,19 @@ class FormElementTestCase extends DrupalWebTestCase {
+
+  /**
+   * Tests Weight form element #default_value behavior.
+   */
+  public function testWeightDefaultValue() {
+    $element = array(
+      '#type' => 'weight',
+      '#delta' => 10,
+      '#default_value' => 15,
+    );
+    $element = form_process_weight($element);
+    $this->assertTrue(isset($element['#options'][$element['#default_value']]), 'Default value exists in #options list');
+  }
 }
 

Not really sure about what else we need to backport. This introduced test reproduce same steps.
The difference is that D8 test uses Weight render class method which has more requirements that just pass render element definition.
But the important part what the test check is the same as in D8 test version - the #options values have to introduce the #default_value which has absolute value larger then #delta absolute value.

Just set the tests against PHP 5.3 and 7.3

voleger’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

There are no patch related errors in the test reports.
#3047844: [Regression] Tests fail on PHP 5.3 and #3025335: session_id() cannot be changed after session is started exists to address test failures in HEAD.
So there no tests to backport. Return RTBC status.

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs work

the tests to backport are from D8, this D8 commit:

here's the patch with the tests we need to backport to D7:

see comment #565220-38: Fix Weight form element behavior

joseph.olstad’s picture

Does this test or it's equivalent (something similar) exist in D7? If so, then no need to backport.

+++ b/core/tests/Drupal/Tests/Core/Render/Element/WeightTest.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Drupal\Tests\Core\Render\Element;
+
+use Drupal\Core\Form\FormState;
+use Drupal\Core\Render\Element\Weight;
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Render\Element\Weight
+ * @group Render
+ */
+class WeightTest extends KernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = ['system'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->installConfig(['system']);
+  }
+
+  /**
+   * Test existing #default_value value in #options list.
+   *
+   * @covers ::processWeight
+   */
+  public function testProcessWeight() {
+    $element = [];
+    $form_state = new FormState();
+    $complete_form = [];
+
+    $element_object = new Weight([], 'weight', []);
+    $info = $element_object->getInfo();
+    $element += $info;
+
+    $element['#default_value'] = $element['#delta'] + 5;
+
+    Weight::processWeight($element, $form_state, $complete_form);
+
+    $this->assertTrue(
+      isset($element['#options'][$element['#default_value']]),
+      'Default value exists in the #options list'
+    );
+  }
+
+}
joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community

Ah ok sorry yes we have tests, see voleger comment #20 #2946801-20: [D7] Fix Weight form element behavior

Thanks

joseph.olstad’s picture

Issue tags: +Pending Drupal 7 commit

Justification:

1) This fix is in D8 already
2) The patch has tests.
3) No change record is required (this is a bug fix)

mustanggb’s picture

Issue tags: -Drupal 7.68 target +Drupal 7.69 target
mustanggb’s picture

Issue tags: -Drupal 7.69 target +Drupal 7.70 target
voleger’s picture

Title: Fix Weight form element behavior [D7] » [D7] Fix Weight form element behavior
Issue tags: -Drupal 7.70 target +Drupal 7.74 target

voleger’s picture

Created a merge request. I hope this will help with the final review.

Also, the merge request creates a tugboat instance, so here steps to reproduce for manual testing:

- Login as the user with permission to edit block layout configuration.
- go to the block layout page.
- add for some testing region 40 blocks and save the configuration.
- change the mode of weight element on the page from draggable elements to the weight input fields.
- try to remove one of the blocks in the testing region and save the configuration.

Expected results (behavior with a patch applied): no weight values changed for the blocks in the testing region.

Current result (behavior in the current core version): some of the blocks had changed weight value in the testing region, which breaks the site builder expectation of the configuration result.

voleger’s picture

joseph.olstad’s picture

mcdruid’s picture

StatusFileSize
new721 bytes
new1.51 KB

Copies of test only patch from #5 and patch from #10 for a fresh round of tests.

Sorry, I've not had a chance to learn my way around merge requests on d.o yet.

The last submitted patch, 33: 2946801-33_copy_5_test-only.patch, failed testing. View results

mcdruid’s picture

StatusFileSize
new718 bytes

Erm the test only patch looks a bit broken actually.

Here's another which is just the test from #10.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: 2946801-35_test_only.patch, failed testing. View results

mcdruid’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Pending Drupal 7 commit +Drupal 7 bugfix target

It's a shame this is so laborious to test manually ("add 40 blocks..." ;)

However the patch makes sense and matches what was committed to D8, plus test looks good.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: 2946801-35_test_only.patch, failed testing. View results

mcdruid’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.51 KB

Hmm we don't want the test only patch to keep failing. Copy of #10 again which should pass and keep this at RTBC.

fabianx’s picture

RTBM, +1 from me for merge

Not seeing any conflicts that could arise except for hidden elements to suddenly show up.

Needs a good release notes notice.

  • mcdruid committed db7208a on 7.x
    Issue #2946801 by voleger, mcdruid, joseph.olstad, MustangGB, andypost,...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Drupal 7.76 target, -Drupal 7 bugfix target

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.