Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion WordPress/Classes/Models/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,21 @@ - (void)setXmlrpc:(NSString *)xmlrpc

- (NSString *)version
{
return [self getOptionValue:@"software_version"];
// Ensure the value being returned is a string to prevent a crash when using this value in Swift
id value = [self getOptionValue:@"software_version"];

// If its a string, then return its value 🎉
if([value isKindOfClass:NSString.class]) {
return value;
}

// If its not a string, but can become a string, then convert it
if([value respondsToSelector:@selector(stringValue)]) {
return [value stringValue];
}

// If the value is an unknown type, and can not become a string, then default to a blank string.
return @"";
}

- (NSString *)password
Expand Down
8 changes: 4 additions & 4 deletions WordPress/WordPressTest/BlogBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ final class BlogBuilder {

func withJetpack(version: String? = nil, username: String? = nil, email: String? = nil) -> Self {
set(blogOption: "jetpack_client_id", value: 1)
set(blogOption: "jetpack_version", value: version)
set(blogOption: "jetpack_user_login", value: username)
set(blogOption: "jetpack_user_email", value: email)
set(blogOption: "jetpack_version", value: version as Any)
set(blogOption: "jetpack_user_login", value: username as Any)
set(blogOption: "jetpack_user_email", value: email as Any)
return set(blogOption: "is_automated_transfer", value: false)
}

Expand Down Expand Up @@ -84,7 +84,7 @@ final class BlogBuilder {
}

@discardableResult
private func set(blogOption key: String, value: Any) -> Self {
func set(blogOption key: String, value: Any) -> Self {
var options = blog.options ?? [AnyHashable: Any]()
options[key] = [
"value": value
Expand Down
31 changes: 31 additions & 0 deletions WordPress/WordPressTest/BlogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ final class BlogTests: XCTestCase {
super.tearDown()
}


// MARK: - Atomic Tests
func testIsAtomic() {
let blog = BlogBuilder(context)
.with(atomic: true)
Expand All @@ -32,6 +34,7 @@ final class BlogTests: XCTestCase {
XCTAssertFalse(blog.isAtomic())
}

// MARK: - Blog Lookup
func testThatLookupByBlogIDWorks() throws {
let blog = BlogBuilder(context).build()
XCTAssertNotNil(blog.dotComID)
Expand Down Expand Up @@ -135,4 +138,32 @@ final class BlogTests: XCTestCase {

XCTAssertFalse(blog.supports(.pluginManagement))
}

// MARK: - Blog.version string conversion testing
func testTheVersionIsAStringWhenGivenANumber() {
let blog = BlogBuilder(context)
.set(blogOption: "software_version", value: 13.37)
.build()

XCTAssertTrue((blog.version as Any) is String)
XCTAssertEqual(blog.version, "13.37")
}

func testTheVersionIsAStringWhenGivenAString() {
let blog = BlogBuilder(context)
.set(blogOption: "software_version", value: "5.5")
.build()

XCTAssertTrue((blog.version as Any) is String)
XCTAssertEqual(blog.version, "5.5")
}

func testTheVersionDefaultsToAnEmptyStringWhenTheValueIsNotConvertible() {
let blog = BlogBuilder(context)
.set(blogOption: "software_version", value: NSObject())
.build()

XCTAssertTrue((blog.version as Any) is String)
XCTAssertEqual(blog.version, "")
}
}
4 changes: 2 additions & 2 deletions config/Version.internal.xcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_SHORT=17.7
VERSION_SHORT=17.7.1

// Internal long version example: VERSION_LONG=9.9.0.20180423
VERSION_LONG=17.7.0.20210709
VERSION_LONG=17.7.1.20210716
4 changes: 2 additions & 2 deletions config/Version.public.xcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_SHORT=17.7
VERSION_SHORT=17.7.1

// Public long version example: VERSION_LONG=9.9.0.0
VERSION_LONG=17.7.0.4
VERSION_LONG=17.7.1.0