Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate method fails after 'setUpdated' method called #22

Closed
mpadge opened this issue Oct 6, 2022 · 2 comments
Closed

validate method fails after 'setUpdated' method called #22

mpadge opened this issue Oct 6, 2022 · 2 comments
Assignees
Labels
bug Something isn't working user support
Milestone

Comments

@mpadge
Copy link

mpadge commented Oct 6, 2022

Context: To test any package which uses atom4R, any attributes of any objects which are dependent on untrollable variables, such as current time or timezone of test environments, must be standardised. It is therefore necessary to be able to set a standard "updated" time using the setUpdated method. Doing so, however, leads to this issue:

library (atom4R)
packageVersion ("atom4R")
#> [1] '0.3.1'

m <- DCEntry$new ()
m$updated
#> [1] "2022-10-06 14:59:56 CEST"
class (m$updated)
#> [1] "POSIXct" "POSIXt"
m$setUpdated (as.POSIXct ("2022-01-01 00:00:01", tz = "CEST"))
m$updated
#> [1] "2022-01-01 00:00:01 CEST"
class (m$updated)
#> [1] "POSIXct" "POSIXt"

At that stage, all looks good, and the updated field has merely changed iternally. But then:

m$validate ()
#> [atom4R][WARN] Element '{http://www.w3.org/2005/Atom}updated', attribute 'tzone': The attribute 'tzone' is not allowed at line 2. 
#> [atom4R][WARN] Object 'DCEntry' is INVALID according to Atom XML schemas!
#> [1] FALSE

And that happens because of the code in the 'validate' method:

self <- m
schemaNamespaceId <- self$namespace$id
xml <- self$encode(addNS = TRUE, validate = FALSE, strict = strict)
print (xml)
#> <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
#>   <atom:updated tzone="CEST">2022-01-01T00:00:01+00:00</atom:updated>
#>   <!--Creation date/time: 2022-10-06T14:59:56-->
#>   <!--Atom XML generated by atom4R R package - Version 0.3-1-->
#>   <!--Atom XML compliance: NOT TESTED-->
#>   <!--atom4R R package information:  Contact: Emmanuel Blondel emmanuel.blondel1@gmail.com   URL: https://github.com/eblondel/atom4R BugReports: https://github.com/eblondel/atom4R-->
#> </atom:entry>
xsd <- getAtomSchemas()
if(is(xml, "XMLInternalNode")) xml <- XML::xmlDoc(xml)
report <- XML::xmlSchemaValidate(xsd, xml)
report$errors[[1]]$msg
#> [1] "Element '{http://www.w3.org/2005/Atom}updated', attribute 'tzone': The attribute 'tzone' is not allowed.\n"
isValid <- report$status == 0 # FALSE

Created on 2022-10-06 with reprex v2.0.2

So atom4R then inserts a tzone="CEST" value into the XML and renders it invalid. Note that in the initial call before setUpdated() is called, then tzone is still there yet empty (so tzone=""). Then the xmlSchemaValidate() method does not complain.

@eblondel
Copy link
Owner

eblondel commented Oct 6, 2022

@mpadge let me know if this fix is enough for you

@eblondel eblondel added bug Something isn't working user support labels Oct 6, 2022
@eblondel eblondel added this to the 0.3 milestone Oct 6, 2022
@eblondel eblondel self-assigned this Oct 6, 2022
@mpadge
Copy link
Author

mpadge commented Oct 6, 2022

Perfect, thanks so much for the super-quick response @eblondel!

@mpadge mpadge closed this as completed Oct 6, 2022
eblondel added a commit that referenced this issue Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working user support
Projects
None yet
Development

No branches or pull requests

2 participants