Skip to content

Commit

Permalink
SF-3187 Store the correct language code when migrating resources
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman committed Feb 3, 2025
1 parent c463df6 commit e4e0f65
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SIL.XForge.Scripture/Services/ParatextService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,9 @@ private void MigrateResourceIfRequired(string username, string paratextId, Langu
if (overrideLanguage is not null)
{
scrText.Settings.LanguageID = overrideLanguage;

// This will create Settings.xml with the correct LanguageIsoCode value
scrText.Settings.Save();
}

// Perform a simple migration of the Paratext 7 LDML file to the new Paratext 8+ location.
Expand Down
20 changes: 20 additions & 0 deletions test/SIL.XForge.Scripture.Tests/Services/ParatextServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4285,6 +4285,15 @@ public async Task SendReceiveAsync_SourceResource_DblLanguageDifferent()
env.MockScrTextCollection.FindById(Arg.Any<string>(), resourceId).Returns(scrText);
ScrTextCollection.Initialize("/srv/scriptureforge/projects");

// The FileManager will be disposed via the using statement in ParatextService.MigrateResourceIfRequired(),
// so capture the saving of the settings here
bool settingsSaved = false;
scrText
.FileManager.When(fm =>
fm.WriteFileCreatingBackup("Settings.xml", Arg.Any<Action<string>>(), Arg.Any<Action<string>>())
)
.Do(_ => settingsSaved = true);

// Set up the mock file system calls used by the migration
env.MockFileSystemService.FileExists(Arg.Is<string>(p => p.EndsWith("ldml.xml"))).Returns(true);
env.MockFileSystemService.FileExists(Arg.Is<string>(p => p.EndsWith(".ldml"))).Returns(false);
Expand All @@ -4305,6 +4314,7 @@ public async Task SendReceiveAsync_SourceResource_DblLanguageDifferent()
env.MockFileSystemService.Received(1)
.MoveFile(Arg.Is<string>(p => p.EndsWith("ldml.xml")), Arg.Is<string>(p => p.EndsWith(".ldml")));
Assert.AreEqual(scrText.Settings.LanguageID.Code, zipLanguageCode);
Assert.IsTrue(settingsSaved);
}

[Test]
Expand Down Expand Up @@ -4338,6 +4348,15 @@ public async Task SendReceiveAsync_SourceResource_DblLanguageMissing()
env.MockScrTextCollection.FindById(Arg.Any<string>(), resourceId).Returns(scrText);
ScrTextCollection.Initialize("/srv/scriptureforge/projects");

// The FileManager will be disposed via the using statement in ParatextService.MigrateResourceIfRequired(),
// so capture the saving of the settings here
bool settingsSaved = false;
scrText
.FileManager.When(fm =>
fm.WriteFileCreatingBackup("Settings.xml", Arg.Any<Action<string>>(), Arg.Any<Action<string>>())
)
.Do(_ => settingsSaved = true);

// Set up the mock file system calls used by the migration
env.MockFileSystemService.FileExists(Arg.Is<string>(p => p.EndsWith("ldml.xml"))).Returns(true);
env.MockFileSystemService.FileExists(Arg.Is<string>(p => p.EndsWith(".ldml"))).Returns(false);
Expand All @@ -4355,6 +4374,7 @@ public async Task SendReceiveAsync_SourceResource_DblLanguageMissing()
env.MockFileSystemService.Received(1)
.MoveFile(Arg.Is<string>(p => p.EndsWith("ldml.xml")), Arg.Is<string>(p => p.EndsWith(".ldml")));
Assert.AreEqual(resourceScrText.Settings.LanguageID?.Code, "en");
Assert.IsTrue(settingsSaved);
}

[Test]
Expand Down

0 comments on commit e4e0f65

Please sign in to comment.