mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-31 12:47:43 +00:00
feat(ios): Fixes new tests, adds 10.0 migration tests
This commit is contained in:
parent
4d9b7d992d
commit
afc385521c
8 changed files with 220 additions and 6 deletions
|
|
@ -179,6 +179,8 @@
|
|||
CE9CD88023FCC1CA002BF2F8 /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE9CD87F23FCC1CA002BF2F8 /* TestUtils.swift */; };
|
||||
CE9CD88323FCC4E3002BF2F8 /* UserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE9CD88223FCC4E3002BF2F8 /* UserDefaults.swift */; };
|
||||
CEDFEF8F23FE43B700BECF39 /* MigrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDFEF8E23FE43B700BECF39 /* MigrationTests.swift */; };
|
||||
CEF888D223FE6ADF00667693 /* No-defaults 10.0 Migration.bundle in Resources */ = {isa = PBXBuildFile; fileRef = CEF888D023FE6ADE00667693 /* No-defaults 10.0 Migration.bundle */; };
|
||||
CEF888D323FE6ADF00667693 /* Simple 10.0 Migration.bundle in Resources */ = {isa = PBXBuildFile; fileRef = CEF888D123FE6ADF00667693 /* Simple 10.0 Migration.bundle */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
|
@ -440,6 +442,8 @@
|
|||
CECB38931F2199BC0098882F /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Reachability.h; path = KeymanEngine/lib/Reachability/Reachability.h; sourceTree = SOURCE_ROOT; };
|
||||
CECB38941F2199BC0098882F /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Reachability.m; path = KeymanEngine/lib/Reachability/Reachability.m; sourceTree = SOURCE_ROOT; };
|
||||
CEDFEF8E23FE43B700BECF39 /* MigrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationTests.swift; sourceTree = "<group>"; };
|
||||
CEF888D023FE6ADE00667693 /* No-defaults 10.0 Migration.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = "No-defaults 10.0 Migration.bundle"; sourceTree = "<group>"; };
|
||||
CEF888D123FE6ADF00667693 /* Simple 10.0 Migration.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = "Simple 10.0 Migration.bundle"; sourceTree = "<group>"; };
|
||||
F243887E14BBD43000A3E055 /* KeymanEngineDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KeymanEngineDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
F243889014BBD43100A3E055 /* KeymanEngine-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KeymanEngine-Prefix.pch"; sourceTree = "<group>"; };
|
||||
F27FCAEE157FD59100FBBA20 /* Keyman-iphoneos.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Keyman-iphoneos.xcconfig"; sourceTree = "<group>"; };
|
||||
|
|
@ -774,6 +778,8 @@
|
|||
CE37C38923FCC9AF007031C6 /* resources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
CEF888D023FE6ADE00667693 /* No-defaults 10.0 Migration.bundle */,
|
||||
CEF888D123FE6ADF00667693 /* Simple 10.0 Migration.bundle */,
|
||||
CE9B440D23FE4E7400499CAB /* 12.0 Ad-hoc Migration.bundle */,
|
||||
CE9B440E23FE4E7500499CAB /* Simple 12.0 Migration.bundle */,
|
||||
CE37C38A23FCC9EE007031C6 /* Keyboards.bundle */,
|
||||
|
|
@ -1158,8 +1164,10 @@
|
|||
CE37C38B23FCC9EE007031C6 /* Keyboards.bundle in Resources */,
|
||||
CE9B441023FE4E7500499CAB /* Simple 12.0 Migration.bundle in Resources */,
|
||||
9ADC45A022E1895D004C78C6 /* LanguageLMDetailViewController.xib in Resources */,
|
||||
CEF888D223FE6ADF00667693 /* No-defaults 10.0 Migration.bundle in Resources */,
|
||||
CE9B440F23FE4E7500499CAB /* 12.0 Ad-hoc Migration.bundle in Resources */,
|
||||
9A0FCA0922D7C58B00D33F86 /* Keyman.bundle in Resources */,
|
||||
CEF888D323FE6ADF00667693 /* Simple 10.0 Migration.bundle in Resources */,
|
||||
CE37C38F23FCD52F007031C6 /* Lexical Models.bundle in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ extension Storage {
|
|||
if paths.isEmpty {
|
||||
return nil
|
||||
}
|
||||
log.info("\(paths[0])")
|
||||
return Storage(baseURL: paths[0], userDefaults: UserDefaults.standard)
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ class MigrationTests: XCTestCase {
|
|||
userDefaults.lastEngineVersion = Version("12.0")!
|
||||
|
||||
let versionResources = TestUtils.Migrations.getVersionHistory(for: Version("12.0")!)
|
||||
userDefaults.userKeyboards?.append(versionResources[0] as! InstallableKeyboard)
|
||||
userDefaults.userKeyboards?.append(TestUtils.Keyboards.khmer_angkor)
|
||||
userDefaults.userLexicalModels?.append(versionResources[1] as! InstallableLexicalModel)
|
||||
TestUtils.UserDefaults.addKeyboard(versionResources[0] as! InstallableKeyboard)
|
||||
TestUtils.UserDefaults.addKeyboard(TestUtils.Keyboards.khmer_angkor)
|
||||
TestUtils.UserDefaults.addLexicalModel(versionResources[1] as! InstallableLexicalModel)
|
||||
|
||||
Migrations.updateResources(storage: Storage.active)
|
||||
|
||||
|
|
@ -32,8 +32,9 @@ class MigrationTests: XCTestCase {
|
|||
// v 0.1.2 -> 0.1.4.
|
||||
// Minor surprise (as of 13.0) is that 0.1.2's file actually remains!
|
||||
|
||||
let mtnt = userDefaults.userLexicalModels?[0]
|
||||
XCTAssertEqual(mtnt?.version, "0.1.4")
|
||||
let defaultModel = userDefaults.userLexicalModels![0]
|
||||
XCTAssertEqual(defaultModel.id, Defaults.lexicalModel.id)
|
||||
XCTAssertEqual(defaultModel.version, Defaults.lexicalModel.version)
|
||||
let modelURL = Storage.active.lexicalModelURL(for: TestUtils.LexicalModels.mtnt) // The bundled, 0.1.4 version.
|
||||
XCTAssert(FileManager.default.fileExists(atPath: modelURL.path))
|
||||
}
|
||||
|
|
@ -43,7 +44,7 @@ class MigrationTests: XCTestCase {
|
|||
|
||||
let userDefaults = Storage.active.userDefaults
|
||||
userDefaults.lastEngineVersion = Version("12.0")!
|
||||
userDefaults.userKeyboards?.append(TestUtils.Keyboards.khmer10)
|
||||
TestUtils.UserDefaults.addKeyboard(TestUtils.Keyboards.khmer10)
|
||||
|
||||
Migrations.migrate(storage: Storage.active)
|
||||
|
||||
|
|
@ -58,4 +59,53 @@ class MigrationTests: XCTestCase {
|
|||
let kmpURL = URL(fileURLWithPath: documentsContents[0])
|
||||
XCTAssertEqual(kmpURL.lastPathComponent, "khmer10.kmp")
|
||||
}
|
||||
|
||||
func testVersion10ResourceMigration() {
|
||||
TestUtils.Migrations.applyBundleToFileSystem(TestUtils.Migrations.simple_10)
|
||||
|
||||
let userDefaults = Storage.active.userDefaults
|
||||
TestUtils.UserDefaults.addKeyboard(TestUtils.Migrations.european2)
|
||||
|
||||
Migrations.updateResources(storage: Storage.active)
|
||||
|
||||
// The old keyboard should be gone entirely, replaced by the current version's default resources.
|
||||
// There should only be one default resource per type (at least, as of 13.0.)
|
||||
XCTAssertEqual(userDefaults.userKeyboards!.count, 1, "Unexpected keyboard count after migration!")
|
||||
// 3, b/c all language-code variants are counted.
|
||||
XCTAssertEqual(userDefaults.userLexicalModels!.count, 3, "Unexpected lexical model count after migration!")
|
||||
|
||||
let defaultKeyboard = userDefaults.userKeyboards![0]
|
||||
XCTAssertNotEqual(TestUtils.Migrations.european2.id, defaultKeyboard.id) // Double-ensure that the ID is new.
|
||||
XCTAssertEqual(defaultKeyboard.id, Defaults.keyboard.id)
|
||||
XCTAssertEqual(defaultKeyboard.version, Defaults.keyboard.version)
|
||||
|
||||
let defaultModel = userDefaults.userLexicalModels![0]
|
||||
XCTAssertEqual(defaultModel.id, Defaults.lexicalModel.id)
|
||||
XCTAssertEqual(defaultModel.version, Defaults.lexicalModel.version)
|
||||
|
||||
let keyboardURL = Storage.active.keyboardURL(for: Defaults.keyboard)
|
||||
let modelURL = Storage.active.lexicalModelURL(for: Defaults.lexicalModel)
|
||||
XCTAssert(FileManager.default.fileExists(atPath: keyboardURL.path))
|
||||
XCTAssert(FileManager.default.fileExists(atPath: modelURL.path))
|
||||
}
|
||||
|
||||
func testNoDefaultVersion10ResourceMigration() {
|
||||
TestUtils.Migrations.applyBundleToFileSystem(TestUtils.Migrations.noDefault_10)
|
||||
|
||||
let userDefaults = Storage.active.userDefaults
|
||||
TestUtils.UserDefaults.addKeyboard(TestUtils.Keyboards.khmer_angkor)
|
||||
|
||||
Migrations.updateResources(storage: Storage.active)
|
||||
|
||||
// No new resources should be installed - only what was originally present should be there.
|
||||
XCTAssertEqual(userDefaults.userKeyboards!.count, 1, "Unexpected keyboard count after migration!")
|
||||
// There was no prior lexical model installed, so the installation still proceeds. The user just won't see it.
|
||||
XCTAssertNil(userDefaults.userLexicalModels, "Unexpected lexical model(s) installed after migration!")
|
||||
|
||||
let keyboard = userDefaults.userKeyboards![0]
|
||||
XCTAssertEqual(keyboard.id, TestUtils.Keyboards.khmer_angkor.id, "Unexpected keyboard was installed after migration!")
|
||||
XCTAssertEqual(keyboard.version, TestUtils.Keyboards.khmer_angkor.version)
|
||||
|
||||
// If successful, confirms that the current default resources are not installed - as expected.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,20 @@ extension TestUtils {
|
|||
// Bundle references
|
||||
static let simple_12 = TestUtils.findSubBundle(forResource: "Simple 12.0 Migration", ofType: ".bundle")
|
||||
static let adhoc_12 = TestUtils.findSubBundle(forResource: "12.0 Ad-hoc Migration", ofType: ".bundle")
|
||||
static let simple_10 = TestUtils.findSubBundle(forResource: "Simple 10.0 Migration", ofType: ".bundle")
|
||||
static let noDefault_10 = TestUtils.findSubBundle(forResource: "No-defaults 10.0 Migration", ofType: ".bundle")
|
||||
|
||||
// The default keyboard in version 10.0.
|
||||
static let european2_font = Font(family: "LatinWeb", source: ["DejaVuSans.ttf"], size: nil)
|
||||
static let european2 = InstallableKeyboard(id: "european2",
|
||||
name: "EuroLatin2 Keyboard",
|
||||
languageID: "en",
|
||||
languageName: "English",
|
||||
version: "1.6",
|
||||
isRTL: false,
|
||||
font: european2_font,
|
||||
oskFont: nil,
|
||||
isCustom: false)
|
||||
|
||||
static func applyBundleToFileSystem(_ bundle: Bundle) {
|
||||
let fileManager = FileManager.default
|
||||
|
|
|
|||
|
|
@ -45,5 +45,35 @@ extension TestUtils {
|
|||
userDefaults.synchronize()
|
||||
userDefaults.removePersistentDomain(forName: domain)
|
||||
}
|
||||
|
||||
static func addKeyboard(_ keyboard: InstallableKeyboard) {
|
||||
// Lifted from Manager.addKeyboard
|
||||
let userDefaults = Storage.active.userDefaults
|
||||
var userKeyboards = userDefaults.userKeyboards ?? []
|
||||
|
||||
// Update keyboard if it exists
|
||||
if let index = userKeyboards.firstIndex(where: { $0.fullID == keyboard.fullID }) {
|
||||
userKeyboards[index] = keyboard
|
||||
} else {
|
||||
userKeyboards.append(keyboard)
|
||||
}
|
||||
|
||||
userDefaults.userKeyboards = userKeyboards
|
||||
}
|
||||
|
||||
static func addLexicalModel(_ lexicalModel: InstallableLexicalModel) {
|
||||
// Lifted from Manager.addKeyboard
|
||||
let userDefaults = Storage.active.userDefaults
|
||||
var userModels = userDefaults.userLexicalModels ?? []
|
||||
|
||||
// Update keyboard if it exists
|
||||
if let index = userModels.firstIndex(where: { $0.fullID == lexicalModel.fullID }) {
|
||||
userModels[index] = lexicalModel
|
||||
} else {
|
||||
userModels.append(lexicalModel)
|
||||
}
|
||||
|
||||
userDefaults.userLexicalModels = userModels
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue