diff --git a/src/System Application/Test/Data Administration/src/MediaCleanupTest.Codeunit.al b/src/System Application/Test/Data Administration/src/MediaCleanupTest.Codeunit.al index 8238d7955e..891d377b5a 100644 --- a/src/System Application/Test/Data Administration/src/MediaCleanupTest.Codeunit.al +++ b/src/System Application/Test/Data Administration/src/MediaCleanupTest.Codeunit.al @@ -160,6 +160,46 @@ codeunit 135018 "Media Cleanup Test" LibraryAssert.IsTrue(TempTenantMedia.IsEmpty(), 'Detached Tenant media was not cleaned up properly.'); end; + [Test] + procedure EnsureNormalMediaArePersisted() + var + TenantMedia: Record "Tenant Media"; + TenantMediaSetup: Record "Tenant Media Set"; + TestMediaClean: Record "Test Media Cleanup"; + TempBlob: Codeunit "Temp Blob"; + MediaOutStream: OutStream; + i: Integer; + begin + PermissionsMock.Set('SUPER'); + + TestMediaClean.Insert(); + + TempBlob.CreateOutStream(MediaOutStream); + MediaOutStream.WriteText('123'); + TestMediaClean."Test Media".ImportStream(TempBlob.CreateInStream(), ''); + TestMediaClean.Modify(); + + clear(TempBlob); + TempBlob.CreateOutStream(MediaOutStream); + for i := 0 to 99 do + MediaOutStream.WriteText('123'); + TestMediaClean."Test Media Set".ImportStream(TempBlob.CreateInStream(), ''); + TestMediaClean.Modify(); + + LibraryAssert.IsTrue(TestMediaClean."Test Media".HasValue(), 'Tenant Media is not correctly inserted.'); + LibraryAssert.IsTrue(TestMediaClean."Test Media Set".Count() > 0, 'Tenant Media Set is not correctly inserted.'); + LibraryAssert.IsFalse(TenantMedia.IsEmpty(), 'Tenant Media is not correctly inserted.'); + LibraryAssert.IsFalse(TenantMediaSetup.IsEmpty(), 'Tenant Media Set is not correctly inserted.'); + + Codeunit.Run(Codeunit::"Media Cleanup Runner"); + + LibraryAssert.IsFalse(TenantMedia.IsEmpty(), 'Normal tenant media is also affected.'); + LibraryAssert.IsFalse(TenantMediaSetup.IsEmpty(), 'Normal tenant media set is also affected.'); + + PermissionsMock.ClearAssignments(); + end; + + local procedure GetDetachedTenantMedia(var TempTenantMedia: Record "Tenant Media" temporary) var MediaCleanup: Codeunit "Media Cleanup"; diff --git a/src/System Application/Test/Data Administration/src/TestMediaCleanup.Table.al b/src/System Application/Test/Data Administration/src/TestMediaCleanup.Table.al new file mode 100644 index 0000000000..6d85e8d007 --- /dev/null +++ b/src/System Application/Test/Data Administration/src/TestMediaCleanup.Table.al @@ -0,0 +1,34 @@ +// ------------------------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// ------------------------------------------------------------------------------------------------ + +namespace System.Test.DataAdministration; + +table 135018 "Test Media Cleanup" +{ + DataClassification = CustomerContent; + InherentPermissions = RIMDX; + InherentEntitlements = RIMDX; + + fields + { + field(1; "Primary Key"; Integer) + { + } + field(2; "Test Media"; Media) + { + } + field(3; "Test Media Set"; MediaSet) + { + } + } + + keys + { + key(PK; "Primary Key") + { + Clustered = true; + } + } +}