PrefabOverrideTestFixture.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Prefab/Overrides/PrefabOverrideTestFixture.h>
  9. namespace UnitTest
  10. {
  11. void PrefabOverrideTestFixture::SetUpEditorFixtureImpl()
  12. {
  13. PrefabTestFixture::SetUpEditorFixtureImpl();
  14. m_prefabOverridePublicInterface = AZ::Interface<PrefabOverridePublicInterface>::Get();
  15. ASSERT_TRUE(m_prefabOverridePublicInterface);
  16. m_prefabFocusPublicInterface = AZ::Interface<PrefabFocusPublicInterface>::Get();
  17. ASSERT_TRUE(m_prefabFocusPublicInterface);
  18. }
  19. void PrefabOverrideTestFixture::CreateEntityInNestedPrefab(
  20. AZ::EntityId& newEntityId, AZ::EntityId& parentContainerId, AZ::EntityId& grandparentContainerId)
  21. {
  22. AZ::EntityId entityUnderRootId = CreateEditorEntityUnderRoot("EntityUnderPrefab");
  23. AZ::IO::Path path;
  24. m_settingsRegistryInterface->Get(path.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder);
  25. AZ::EntityId nestedPrefabContainerId = CreateEditorPrefab(path, AzToolsFramework::EntityIdList{ entityUnderRootId });
  26. // Append '1' to the path so that there is no path collision when creating another prefab.
  27. grandparentContainerId = CreateEditorPrefab(path.Append("1"), AzToolsFramework::EntityIdList{ nestedPrefabContainerId });
  28. PropagateAllTemplateChanges();
  29. InstanceOptionalReference prefabInstance = m_instanceEntityMapperInterface->FindOwningInstance(grandparentContainerId);
  30. EXPECT_TRUE(prefabInstance.has_value());
  31. // Fetch the id of the entity within the nested prefab as it changes after putting it in a prefab.
  32. prefabInstance->get().GetNestedInstances(
  33. [&newEntityId, &parentContainerId](AZStd::unique_ptr<Instance>& nestedInstance)
  34. {
  35. nestedInstance->GetEntities(
  36. [&newEntityId](const AZStd::unique_ptr<AZ::Entity>& entity)
  37. {
  38. newEntityId = entity->GetId();
  39. return true;
  40. });
  41. parentContainerId = nestedInstance->GetContainerEntityId();
  42. });
  43. }
  44. void PrefabOverrideTestFixture::CreateAndValidateEditEntityOverride(AZ::EntityId entityId, AZ::EntityId ancestorEntityId)
  45. {
  46. m_prefabFocusPublicInterface->FocusOnOwningPrefab(ancestorEntityId);
  47. // Validate that there are no overrides present on the entity.
  48. ASSERT_FALSE(m_prefabOverridePublicInterface->AreOverridesPresent(entityId));
  49. // Modify the transform component.
  50. AZ::TransformBus::Event(entityId, &AZ::TransformInterface::SetWorldX, 10.0f);
  51. m_prefabPublicInterface->GenerateUndoNodesForEntityChangeAndUpdateCache(entityId, m_undoStack->GetTop());
  52. // Validate that override is present on the entity.
  53. EXPECT_TRUE(m_prefabOverridePublicInterface->AreOverridesPresent(entityId));
  54. }
  55. void PrefabOverrideTestFixture::EditEntityAndValidateNoOverride(AZ::EntityId entityId)
  56. {
  57. m_prefabFocusPublicInterface->FocusOnOwningPrefab(entityId);
  58. // Validate that there are no overrides present on the entity.
  59. ASSERT_FALSE(m_prefabOverridePublicInterface->AreOverridesPresent(entityId));
  60. // Modify the transform component.
  61. AZ::TransformBus::Event(entityId, &AZ::TransformInterface::SetWorldX, 10.0f);
  62. m_prefabPublicInterface->GenerateUndoNodesForEntityChangeAndUpdateCache(entityId, m_undoStack->GetTop());
  63. // Validate that overrides are still not present on the entity since the edit went to the template DOM directly.
  64. EXPECT_FALSE(m_prefabOverridePublicInterface->AreOverridesPresent(entityId));
  65. }
  66. } // namespace UnitTest