From 5ba055956e6052785fd4f8fedd5d819d45ad88f0 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Tue, 24 Oct 2017 22:07:21 +0100 Subject: [PATCH 1/3] Add test to check fail scenario. --- AztecTests/TextKit/TextViewTests.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/AztecTests/TextKit/TextViewTests.swift b/AztecTests/TextKit/TextViewTests.swift index ab48a6508..82e7dd4cc 100644 --- a/AztecTests/TextKit/TextViewTests.swift +++ b/AztecTests/TextKit/TextViewTests.swift @@ -1776,4 +1776,30 @@ class TextViewTests: XCTestCase { XCTAssert(textView.getHTML(prettyPrint: false) == expected) } + /// This test verifies that attributes on media attachment are being removed properly. + /// of text that never had H1 style, to begin with!. + /// + func testAttributesOnMediaAttachmentsAreRemoved() { + let textView = createTextView(withHTML: "") + + guard let attachment = textView.storage.mediaAttachments.first else { + XCTFail("There must be an attachment") + return + } + + guard let attributedValue = attachment.extraAttributes["data-wp_upload_id"] else { + XCTFail("There must be an attribute with the name data-wp_upload_i") + return + } + + XCTAssertEqual(attributedValue, "ABCDE") + + // Remove attribute + attachment.extraAttributes["data-wp_upload_id"] = nil + + let html = textView.getHTML() + + XCTAssertEqual(html, "

" ) + } + } From e9c424874b8bd30ff79f2bfabd400af88a5c2ae9 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Tue, 24 Oct 2017 22:47:56 +0100 Subject: [PATCH 2/3] Ignore original HTML representation on MediaAttachments. --- .../Formatters/Implementations/ImageFormatter.swift | 2 +- .../Formatters/Implementations/VideoFormatter.swift | 2 +- AztecTests/TextKit/TextViewTests.swift | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Aztec/Classes/Formatters/Implementations/ImageFormatter.swift b/Aztec/Classes/Formatters/Implementations/ImageFormatter.swift index c96db516a..16aef9107 100644 --- a/Aztec/Classes/Formatters/Implementations/ImageFormatter.swift +++ b/Aztec/Classes/Formatters/Implementations/ImageFormatter.swift @@ -64,6 +64,6 @@ class ImageFormatter: StandardAttributeFormatter { } } - return super.apply(to: attributes, andStore: representation) + return super.apply(to: attributes, andStore: nil) } } diff --git a/Aztec/Classes/Formatters/Implementations/VideoFormatter.swift b/Aztec/Classes/Formatters/Implementations/VideoFormatter.swift index 0205992e9..d9299235f 100644 --- a/Aztec/Classes/Formatters/Implementations/VideoFormatter.swift +++ b/Aztec/Classes/Formatters/Implementations/VideoFormatter.swift @@ -53,6 +53,6 @@ class VideoFormatter: StandardAttributeFormatter { assert(representation == nil) } - return super.apply(to: attributes, andStore: representation) + return super.apply(to: attributes, andStore: nil) } } diff --git a/AztecTests/TextKit/TextViewTests.swift b/AztecTests/TextKit/TextViewTests.swift index 82e7dd4cc..6d08c38e6 100644 --- a/AztecTests/TextKit/TextViewTests.swift +++ b/AztecTests/TextKit/TextViewTests.swift @@ -1567,7 +1567,7 @@ class TextViewTests: XCTestCase { let html = "\"Alt\"" let textView = createTextView(withHTML: html) - XCTAssertEqual(textView.getHTML(), "

\"Alt\"

") + XCTAssertEqual(textView.getHTML(), "

\"Alt\"

") guard let attachment = textView.storage.mediaAttachments.first as? ImageAttachment else { XCTFail("An video attachment should be present") @@ -1579,7 +1579,7 @@ class TextViewTests: XCTestCase { attachment.extraAttributes["alt"] = "Changed Alt" attachment.extraAttributes["class"] = "wp-image-169" - XCTAssertEqual(textView.getHTML(), "

\"Changed

") + XCTAssertEqual(textView.getHTML(), "

\"Changed

") } @@ -1609,7 +1609,7 @@ class TextViewTests: XCTestCase { /// This test verifies that img class attributes are not duplicated /// func testParseImageDoesntDuplicateExtraAttributes() { - let html = "\"Alt\"" + let html = "\"Alt\"" let textView = createTextView(withHTML: html) let generatedHTML = textView.getHTML() @@ -1780,7 +1780,7 @@ class TextViewTests: XCTestCase { /// of text that never had H1 style, to begin with!. /// func testAttributesOnMediaAttachmentsAreRemoved() { - let textView = createTextView(withHTML: "") + let textView = createTextView(withHTML: "") guard let attachment = textView.storage.mediaAttachments.first else { XCTFail("There must be an attachment") @@ -1799,7 +1799,7 @@ class TextViewTests: XCTestCase { let html = textView.getHTML() - XCTAssertEqual(html, "

" ) + XCTAssertEqual(html, "

" ) } } From 0ece4641f65ae1d7978d5ed5c505a8afbcee5d6e Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Mon, 30 Oct 2017 14:48:41 +0000 Subject: [PATCH 3/3] Add comment to explain better the intent of code. --- Aztec/Classes/Formatters/Implementations/ImageFormatter.swift | 2 +- Aztec/Classes/Formatters/Implementations/VideoFormatter.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Aztec/Classes/Formatters/Implementations/ImageFormatter.swift b/Aztec/Classes/Formatters/Implementations/ImageFormatter.swift index 16aef9107..c79dab894 100644 --- a/Aztec/Classes/Formatters/Implementations/ImageFormatter.swift +++ b/Aztec/Classes/Formatters/Implementations/ImageFormatter.swift @@ -63,7 +63,7 @@ class ImageFormatter: StandardAttributeFormatter { attributeValue = ImageAttachment(identifier: UUID().uuidString) } } - + // Comment: Sergio Estevao (2017-10-30) - We are not passing the representation because it's all save inside the extraAttributes property of the attachment. return super.apply(to: attributes, andStore: nil) } } diff --git a/Aztec/Classes/Formatters/Implementations/VideoFormatter.swift b/Aztec/Classes/Formatters/Implementations/VideoFormatter.swift index d9299235f..7959d58b8 100644 --- a/Aztec/Classes/Formatters/Implementations/VideoFormatter.swift +++ b/Aztec/Classes/Formatters/Implementations/VideoFormatter.swift @@ -52,7 +52,7 @@ class VideoFormatter: StandardAttributeFormatter { // assert(representation == nil) } - + // Comment: Sergio Estevao (2017-10-30) - We are not passing the representation because it's all save inside the extraAttributes property of the attachment. return super.apply(to: attributes, andStore: nil) } }