Problem/Motivation

taxonomy_term_save() used to accept an array of arrays of Term IDs for $term->parent, but, as stated by @Berdir in #9, support was removed in the taxonomy entity class conversion patch, but there aren't any tests. We should write tests.

See the Change Record Entities are now classed objects using a defined interface for more information about what happened to taxonomy_term_save().

Proposed resolution

Write tests if they do not exist already.

Remaining tasks

  1. Determine if there are already tests to cover this
  2. If not, write them

User interface changes

None.

API changes

None.

Original report by @mr.baileys

While working on #1162226: taxonomy_term_save should document what is in a $term object, I noticed that taxonomy_term_save() currently supports the following values for $term->parent:

  1. A single tid
  2. An array of tids
  3. An array of arrays of tids

I briefly talked to catch on IRC and couldn't really figure out why we should accept an array of arrays of tids. The tests run fine just supporting 1. and 2., and so does devel generate-terms.

My guess is that this is a left-over from how taxonomy_save_terms() used to be fed input straight form the form API (see #17955: Remove use of form_item() in taxonomy where this array of arrays support was introduced), so I suggest removing it.

Comments

catch’s picture

Subscribing, this should work fine with multiple parents since that's what the overall foreach is for, but I'd like to double check we have tests for assigning multiple parents before marking RTBC.

kscheirer’s picture

Status: Needs review » Needs work

The last submitted patch, 0001-Remove-support-for-nested-arrays-for-term-parent-fro.patch, failed testing.

xjm’s picture

Issue tags: +Needs tests, +Novice

Tagging novice to reroll against current 8.x. Thanks!

cosmicdreams’s picture

StatusFileSize
new868 bytes

rerolled

cosmicdreams’s picture

Status: Needs work » Needs review

setting to review so test bot can test

berdir’s picture

Issue tags: -Needs tests, -Novice

#5: 1175156-4-taxonomy.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs tests, +Novice

The last submitted patch, 1175156-4-taxonomy.patch, failed testing.

berdir’s picture

We actually removed support for that in the taxonomy entity class conversion patch, see http://api.drupal.org/api/drupal/core%21modules%21taxonomy%21taxonomy.en....

Not sure if we want to close this as a duplicate or change to a task to add tests...

dags’s picture

Assigned: Unassigned » dags
dags’s picture

Assigned: dags » Unassigned
mparker17’s picture

Assigned: Unassigned » mparker17
Issue summary: View changes
Issue tags: +Needs issue summary update

Adding tests sounds like a good idea: marking as "Needs issue summary update".

I want to learn how to write automated tests: assigning to myself.

mparker17’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated issue summary.

mparker17’s picture

Issue summary: View changes

Adding notes.

mparker17’s picture

Assigned: mparker17 » Unassigned

Based on @lauriii's suggestion in IRC, this issue may not be relevant anymore, so I'm going to skip it for now.

Here's some code that might work in a test class that extends \Drupal\taxonomy\Tests\TaxonomyTestBase:

  /**
   * Tests that it's not possible to create a term with an array of an array of
   * parent IDs.
   */
  function testArrayOfArraysOfParentTids() {
    $vocabulary = $this->createVocabulary();
    $parent_term1 = $this->createTerm($vocabulary);
    $parent_term2 = $this->createTerm($vocabulary);
    $child_term = $this->createTerm($vocabulary);
    $child_term->parent = array(array($parent_term1->id(), $parent_term2->id()));
    $child_term->save();
  }
dcam’s picture

Issue tags: -Needs tests, -Novice

Removing the Novice tag in prep for the DrupalCon Austin sprints. Both tags were already removed in #7, but Testbot added them back in.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

catch’s picture

Title: Remove nested array support for $term->parent from taxonomy_term_save(). » Tests for $term->parent in Term::save()
Category: Bug report » Task
Issue tags: +Bug Smash Initiative

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.