Closed Pen-a11y closed 2 years ago
Initially the ContentHelper using the DOM Module does not need to be more than a list of functions. A set of unit tests will verify they behave as expected. When the functionality is as required, it can be integrated within the plugin.
get_images(string $html): DOMElement[]
Given a html string, either an entire or partial document, return all image elements (these can be DOMElement instances)
get_image_caption(DOMElement $element): ?string
Given a DOMElement node, return either null or its caption
get_image_alt(DOMElement $element): ?string
Given a DOMElement node, return either null or its alt
get_image_attr_src(DOMElement $element): ?string
Given a DOMElement node, return either null or its src attribute
get_image_attachment_src(DOMElement $element): ?string
Given a DOMElement node, return either null or its attachment src
_this requires coyote_attachment_url()
, also see if you still want to use something like the existing get_class_attachment_id()
. It might be good to use a mocked coyote_attachment_url()
function within the test._
set_image_alt(DOMElement $element, string $alt): DOMElement
Given an image DOMElement node and a string, set its alt attribute value. Be careful of data sanitation.
set_image_alts(string $html, []<string => string>): string
Given a html string, either an entire or partial document, and a map of image sources and their alt attributes, set the alt text for each image and return the modified html
src => alt
pairssrc
Are there more scenarios you can think of?
So far I have not been able to think of other scenarios to test for. At the moment I have finished many of the functions, and I am in the process of getting the PHPUnit tester to work appropriately.
One question I had was what would the caption of the image be? Is this talking about a <figcaption>
tag within a <figure>
?
Also should there be more functions included within the ContentHelper? As some of these scenarios that are given seem like they would need to be in separate functions then the ones provided above
@jkva I looked into the issue we discussed yesterday of HTML5 not being loaded appropriately with PHP DOM Module, and it was correct.
I was checking to see if there were any alternatives and it looks like the best option is HTML5-PHP
It still lets us load it into a DOM Document, I'd love to hear your input on it as well.
Closing as currently implemented in V2 via the ContentHelper
package.
Currently we are using regular-expression based DOM parsing.
We would like to migrate over to using the DOM Module that is within PHP.
Previously there have been issues using this with WPEngine, but it seems that these problems have been resolved.