Skip to content

Commit 375a7ce

Browse files
committed
canUploadAsset logic changed to handle self hosted sites + overloaded function for easier testing + new unit test
1 parent 7ea0fb2 commit 375a7ce

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

WordPress/Classes/Utility/Media/Blog+VideoLimits.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ extension Blog {
22

33
/// returns true if the blog is allowed to upload the given asset, true otherwise
44
func canUploadAsset(_ asset: WPMediaAsset) -> Bool {
5-
hasPaidPlan || !asset.exceedsFreeSitesAllowance()
5+
return canUploadAsset(asset.exceedsFreeSitesAllowance())
6+
}
7+
8+
public func canUploadAsset(_ assetExceedsFreeSitesAllowance: Bool) -> Bool {
9+
return hasPaidPlan || !isHostedAtWPcom || !assetExceedsFreeSitesAllowance
610
}
711
}

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,7 @@
24132413
DC8F61F727032B3F0087AC5D /* TimeZoneFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8F61F627032B3F0087AC5D /* TimeZoneFormatter.swift */; };
24142414
DC8F61F827032B3F0087AC5D /* TimeZoneFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8F61F627032B3F0087AC5D /* TimeZoneFormatter.swift */; };
24152415
DC8F61FC2703321F0087AC5D /* TimeZoneFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8F61FB2703321F0087AC5D /* TimeZoneFormatterTests.swift */; };
2416+
DCC662512810915D00962D0C /* BlogVideoLimitsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC662502810915D00962D0C /* BlogVideoLimitsTests.swift */; };
24162417
E100C6BB1741473000AE48D8 /* WordPress-11-12.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = E100C6BA1741472F00AE48D8 /* WordPress-11-12.xcmappingmodel */; };
24172418
E10290741F30615A00DAC588 /* Role.swift in Sources */ = {isa = PBXBuildFile; fileRef = E10290731F30615A00DAC588 /* Role.swift */; };
24182419
E102B7901E714F24007928E8 /* RecentSitesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = E102B78F1E714F24007928E8 /* RecentSitesService.swift */; };
@@ -7178,6 +7179,7 @@
71787179
DC76668226FD9AC9009254DD /* TimeZoneTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeZoneTableViewCell.swift; sourceTree = "<group>"; };
71797180
DC8F61F627032B3F0087AC5D /* TimeZoneFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeZoneFormatter.swift; sourceTree = "<group>"; };
71807181
DC8F61FB2703321F0087AC5D /* TimeZoneFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeZoneFormatterTests.swift; sourceTree = "<group>"; };
7182+
DCC662502810915D00962D0C /* BlogVideoLimitsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlogVideoLimitsTests.swift; sourceTree = "<group>"; };
71817183
E100C6BA1741472F00AE48D8 /* WordPress-11-12.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = "WordPress-11-12.xcmappingmodel"; sourceTree = "<group>"; };
71827184
E10290731F30615A00DAC588 /* Role.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Role.swift; sourceTree = "<group>"; };
71837185
E102B78F1E714F24007928E8 /* RecentSitesService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecentSitesService.swift; sourceTree = "<group>"; };
@@ -8327,6 +8329,7 @@
83278329
FF8CD624214184EE00A33A8D /* MediaAssetExporterTests.swift */,
83288330
08F8CD3A1EBD2D020049D0C0 /* MediaURLExporterTests.swift */,
83298331
08E77F461EE9D72F006F9515 /* MediaThumbnailExporterTests.swift */,
8332+
DCC662502810915D00962D0C /* BlogVideoLimitsTests.swift */,
83308333
);
83318334
name = Media;
83328335
sourceTree = "<group>";
@@ -19484,6 +19487,7 @@
1948419487
73B6693A21CAD960008456C3 /* ErrorStateViewTests.swift in Sources */,
1948519488
8BD34F0927D144FF005E931C /* BlogDashboardStateTests.swift in Sources */,
1948619489
1759F1721FE017F20003EC81 /* QueueTests.swift in Sources */,
19490+
DCC662512810915D00962D0C /* BlogVideoLimitsTests.swift in Sources */,
1948719491
3F1AD48123FC87A400BB1375 /* BlogDetailsViewController+MeButtonTests.swift in Sources */,
1948819492
08F8CD3B1EBD2D020049D0C0 /* MediaURLExporterTests.swift in Sources */,
1948919493
D81C2F6220F89632002AE1F1 /* EditCommentActionTests.swift in Sources */,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import XCTest
2+
3+
class BlogVideoLimitsTests: XCTestCase {
4+
5+
private var blog: Blog!
6+
private var contextManager: TestContextManager!
7+
private var context: NSManagedObjectContext!
8+
9+
override func setUpWithError() throws {
10+
contextManager = TestContextManager()
11+
context = contextManager.newDerivedContext()
12+
blog = NSEntityDescription.insertNewObject(forEntityName: "Blog", into: context) as? Blog
13+
blog.url = Constants.blogURL
14+
blog.xmlrpc = Constants.blogURL
15+
}
16+
17+
override func tearDownWithError() throws {
18+
blog = nil
19+
}
20+
21+
func testCanUploadAssetPaidPlan() throws {
22+
// Given a blog
23+
// When blog has a paid plan
24+
blog.hasPaidPlan = true
25+
26+
// Then it can upload assets irrespective of allowance
27+
XCTAssertTrue(blog.canUploadAsset(true))
28+
XCTAssertTrue(blog.canUploadAsset(false))
29+
}
30+
31+
func testCanUploadAssetWPCom() throws {
32+
// Given a blog
33+
// When blog is on WPCom and not paid
34+
blog.isHostedAtWPcom = true
35+
blog.hasPaidPlan = false
36+
37+
// Then it can upload assets when allowance not exceeded
38+
XCTAssertTrue(blog.canUploadAsset(false))
39+
40+
// Then it cannot upload assets when allowance exceeded
41+
XCTAssertFalse(blog.canUploadAsset(true))
42+
}
43+
44+
func testCanUploadAssetSelfHosted() throws {
45+
// Given a blog
46+
// When blog is not on WPCom and not paid
47+
blog.isHostedAtWPcom = false
48+
blog.hasPaidPlan = false
49+
50+
// Then it can upload assets irrespective of allowance
51+
XCTAssertTrue(blog.canUploadAsset(true))
52+
XCTAssertTrue(blog.canUploadAsset(false))
53+
}
54+
}
55+
56+
private extension BlogVideoLimitsTests {
57+
enum Constants {
58+
static let blogURL: String = "http://wordpress.com"
59+
}
60+
}

0 commit comments

Comments
 (0)