divio/django-cms — pull request #1532 by evildmp (2012-11-24 14:43:44+00:00)
Title: fix #1527, more tests

I'd appreciate a review before this is merged.

Fixes #1527 - when plugin trees were copied, their new structure was not always an accurate copy. In most cases this didn't actually have any effects, which is why this escaped so long.

It's likely relevant to #1463 also; one failure I had there was with copied plugin tree problems.

The problem was that in a copy, a plugin could be given the wrong parent - it would become the child of its sibling instead.

New test, test_plugin_deep_nesting_and_copying
=======================================

Creates a structure that the wouldn't be copied accurately before, and tests it thoroughly. It's a long test, but I can't see how to get around that, especially as it tests properties of the tree incrementally as more nodes are added, until finally its copied.

CMSPlugin.copy_plugin()
====================

This is where the heart of the problem was. The routine maintains a kind of breadcrumb trail though the plugin tree to work out a new plugin's parent, but would sometimes lose its way.

Some variables have been renamed to make it easier to understand their purpose; also lots of comments because I think the logic is not easy to follow unless you already know it.

Should be of interest to @adaptivelogic.