|
10 | 10 | from plone.app.testing import SITE_OWNER_NAME |
11 | 11 | from plone.app.testing import SITE_OWNER_PASSWORD |
12 | 12 | from plone.app.textfield.value import RichTextValue |
| 13 | +from plone.dexterity.fti import DexterityFTI |
13 | 14 | from plone.namedfile.file import NamedBlobImage |
14 | 15 | from plone.namedfile.file import NamedImage |
15 | 16 | from Products.CMFPlone.interfaces.constrains import ENABLED |
@@ -411,7 +412,64 @@ def test_import_content_with_missing_folder(self): |
411 | 412 | self.assertIn("folder1", portal.contentIds()) |
412 | 413 | new_folder = portal["folder1"] |
413 | 414 | # The auto generated folder will have its id as title |
414 | | - self.assertEqual(new_folder.Title(), "folder1") |
| 415 | + self.assertEqual(new_folder.Title(), "Folder 1") |
| 416 | + # The document should be back. |
| 417 | + self.assertIn("doc1", new_folder.contentIds()) |
| 418 | + new_doc = new_folder["doc1"] |
| 419 | + self.assertEqual(new_doc.Title(), "Document 1") |
| 420 | + self.assertEqual(new_doc.portal_type, "Document") |
| 421 | + |
| 422 | + def test_import_content_with_missing_container_of_different_type(self): |
| 423 | + # First create some content. |
| 424 | + app = self.layer["app"] |
| 425 | + portal = self.layer["portal"] |
| 426 | + login(app, SITE_OWNER_NAME) |
| 427 | + |
| 428 | + # Create custom container type |
| 429 | + fti = DexterityFTI("Container") |
| 430 | + portal.portal_types._setObject("Container", fti) |
| 431 | + fti.klass = "plone.dexterity.content.Container" |
| 432 | + fti.filter_content_types = False |
| 433 | + fti.behaviors = ("plone.app.dexterity.behaviors.metadata.IBasic",) |
| 434 | + |
| 435 | + folder = api.content.create( |
| 436 | + container=portal, type="Folder", id="folder1", title="Folder 1" |
| 437 | + ) |
| 438 | + api.content.create( |
| 439 | + container=folder, type="Document", id="doc1", title="Document 1" |
| 440 | + ) |
| 441 | + transaction.commit() |
| 442 | + |
| 443 | + # Now export the document. |
| 444 | + browser = self.open_page("@@export_content") |
| 445 | + browser.getControl(name="portal_type").value = ["Document"] |
| 446 | + browser.getForm(action="@@export_content").submit(name="submit") |
| 447 | + raw_data = browser.contents |
| 448 | + if not browser.contents: |
| 449 | + raw_data = DATA[-1] |
| 450 | + |
| 451 | + # Edit the raw data to pretend the parent was not a Folder but a custom container type |
| 452 | + raw_data = raw_data.replace(b'"@type": "Folder"', b'"@type": "Container"') |
| 453 | + |
| 454 | + # Remove both the folder and document. |
| 455 | + api.content.delete(folder) |
| 456 | + transaction.commit() |
| 457 | + self.assertNotIn("folder1", portal.contentIds()) |
| 458 | + |
| 459 | + # Now import the document. |
| 460 | + # The missing folder structure should be created. |
| 461 | + browser = self.open_page("@@import_content") |
| 462 | + upload = browser.getControl(name="jsonfile") |
| 463 | + upload.add_file(raw_data, "application/json", "Document.json") |
| 464 | + browser.getForm(action="@@import_content").submit() |
| 465 | + self.assertIn("Imported 1 items", browser.contents) |
| 466 | + |
| 467 | + # The folder should be back. |
| 468 | + self.assertIn("folder1", portal.contentIds()) |
| 469 | + new_folder = portal["folder1"] |
| 470 | + # The auto generated container will have the parents type and title |
| 471 | + self.assertEqual(new_folder.portal_type, "Container") |
| 472 | + self.assertEqual(new_folder.Title(), "Folder 1") |
415 | 473 | # The document should be back. |
416 | 474 | self.assertIn("doc1", new_folder.contentIds()) |
417 | 475 | new_doc = new_folder["doc1"] |
@@ -463,7 +521,7 @@ def test_import_content_from_other_plone_site(self): |
463 | 521 | self.assertIn("folder1", portal.contentIds()) |
464 | 522 | new_folder = portal["folder1"] |
465 | 523 | # The auto generated folder will have its id as title |
466 | | - self.assertEqual(new_folder.Title(), "folder1") |
| 524 | + self.assertEqual(new_folder.Title(), "Folder 1") |
467 | 525 | # The document should be back. |
468 | 526 | self.assertIn("doc1", new_folder.contentIds()) |
469 | 527 | new_doc = new_folder["doc1"] |
|
0 commit comments