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
4 changes: 2 additions & 2 deletions Aztec/Classes/Formatters/Implementations/ImageFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ImageFormatter: StandardAttributeFormatter {
attributeValue = ImageAttachment(identifier: UUID().uuidString)
}
}

return super.apply(to: attributes, andStore: representation)
// 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)
}
}
4 changes: 2 additions & 2 deletions Aztec/Classes/Formatters/Implementations/VideoFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class VideoFormatter: StandardAttributeFormatter {
//
assert(representation == nil)
}

return super.apply(to: attributes, andStore: representation)
// 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)
}
}
32 changes: 29 additions & 3 deletions AztecTests/TextKit/TextViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ class TextViewTests: XCTestCase {
let html = "<img src=\"image.jpg\" class=\"alignnone\" alt=\"Alt\" title=\"Title\">"
let textView = createTextView(withHTML: html)

XCTAssertEqual(textView.getHTML(), "<p><img src=\"image.jpg\" class=\"alignnone\" alt=\"Alt\" title=\"Title\"></p>")
XCTAssertEqual(textView.getHTML(), "<p><img src=\"image.jpg\" class=\"alignnone\" title=\"Title\" alt=\"Alt\"></p>")

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

XCTAssertEqual(textView.getHTML(), "<p><img src=\"image.jpg\" class=\"alignnone wp-image-169\" alt=\"Changed Alt\" title=\"Title\"></p>")
XCTAssertEqual(textView.getHTML(), "<p><img src=\"image.jpg\" class=\"alignnone wp-image-169\" title=\"Title\" alt=\"Changed Alt\"></p>")
}


Expand Down Expand Up @@ -1609,7 +1609,7 @@ class TextViewTests: XCTestCase {
/// This test verifies that img class attributes are not duplicated
///
func testParseImageDoesntDuplicateExtraAttributes() {
let html = "<img src=\"image.jpg\" class=\"wp-image-test\" alt=\"Alt\" title=\"Title\">"
let html = "<img src=\"image.jpg\" class=\"wp-image-test\" title=\"Title\" alt=\"Alt\">"
let textView = createTextView(withHTML: html)
let generatedHTML = textView.getHTML()

Expand Down Expand Up @@ -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: "<img src=\"http://placeholder\" data-wp_upload_id=\"ABCDE\" >")

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, "<p><img src=\"http://placeholder\"></p>" )
}

}