@@ -223,6 +223,74 @@ def test_add_and_cancel_plugin(self):
223223 response = text_plugin_class .delete_on_cancel (request )
224224 self .assertEqual (response .status_code , 400 )
225225
226+ def test_copy_referenced_plugins (self ):
227+ """
228+ Test that copy+pasting a child plugin between text editors
229+ creates proper copies of the child plugin and messes no other data up
230+ """
231+ simple_page = create_page ('test page' , 'page.html' , u'en' )
232+ simple_placeholder = get_page_placeholders (simple_page , 'en' ).get (slot = 'content' )
233+
234+ def _get_text_plugin_with_children ():
235+ text_plugin = add_plugin (
236+ simple_placeholder ,
237+ 'TextPlugin' ,
238+ 'en' ,
239+ body = 'Text plugin we copy child plugins to'
240+ )
241+ _add_child_plugins_to_text_plugin (text_plugin )
242+ return text_plugin
243+
244+ def _add_child_plugins_to_text_plugin (text_plugin ):
245+ child_plugin_1 = add_plugin (
246+ simple_placeholder ,
247+ 'PicturePlugin' ,
248+ 'en' ,
249+ target = text_plugin ,
250+ picture = self .create_filer_image_object (),
251+ caption_text = 'Child plugin one' ,
252+ )
253+ child_plugin_2 = add_plugin (
254+ simple_placeholder ,
255+ 'PicturePlugin' ,
256+ 'en' ,
257+ target = text_plugin ,
258+ picture = self .create_filer_image_object (),
259+ caption_text = 'Child plugin two' ,
260+ )
261+ self .add_plugin_to_text (text_plugin , child_plugin_1 )
262+ self .add_plugin_to_text (text_plugin , child_plugin_2 )
263+
264+ def _copy_child_plugins_from_text (text_plugin_source , text_plugin_destination ):
265+ for child_plugin in text_plugin_source .cmsplugin_set .all ():
266+ text_plugin_destination .body += ' ' + plugin_to_tag (child_plugin )
267+ text_plugin_destination .save ()
268+ _run_clean_and_copy (text_plugin_destination )
269+
270+ def _run_clean_and_copy (text_plugin ):
271+ text_plugin .clean_plugins ()
272+ text_plugin .copy_referenced_plugins ()
273+
274+ def _get_common_children_ids (text_plugin_one , text_plugin_two ):
275+ original_children_ids = set (plugin_tags_to_id_list (text_plugin_one .body ))
276+ copied_children_ids = set (plugin_tags_to_id_list (text_plugin_two .body ))
277+ return original_children_ids .intersection (copied_children_ids )
278+
279+ text_plugin_copy_from = _get_text_plugin_with_children ()
280+ text_plugin_copy_to = _get_text_plugin_with_children ()
281+
282+ _copy_child_plugins_from_text (text_plugin_copy_from , text_plugin_copy_to )
283+ self .assertEqual (text_plugin_copy_from .cmsplugin_set .count (), 2 )
284+ self .assertEqual (text_plugin_copy_to .cmsplugin_set .count (), 4 )
285+
286+ _run_clean_and_copy (text_plugin_copy_from )
287+ _run_clean_and_copy (text_plugin_copy_to )
288+ self .assertEqual (text_plugin_copy_from .cmsplugin_set .count (), 2 )
289+ self .assertEqual (text_plugin_copy_to .cmsplugin_set .count (), 4 )
290+
291+ common_children_ids = _get_common_children_ids (text_plugin_copy_from , text_plugin_copy_to )
292+ self .assertFalse (common_children_ids )
293+
226294 def test_add_and_cancel_child_plugin (self ):
227295 """
228296 Test that you can add a text plugin
0 commit comments