private Metadata GetMetadata(string dataDivContent, CollectionSettings collectionSettings = null) { var dom = MakeDom(dataDivContent); var bookData = new BookData(dom, collectionSettings ?? _collectionSettings, null); return(BookCopyrightAndLicense.GetMetadata(dom, bookData)); }
private static Metadata GetMetadata(string dataDivContent) { var dom = MakeDom(dataDivContent); //normally, the branding is just a name, which we look up in the official branding folder //but in order to allow unit tests to test particular contents of it, we also allow //it to be a path to a constructed branding folder. //These unit tests can then write to a temp file and point to that. return(BookCopyrightAndLicense.GetMetadata(dom, _brandingFolder.Path)); }
public void AmpersandInOriginalCopyrightHandledProperly() { // See http://issues.bloomlibrary.org/youtrack/issue/BL-4585. var dom = new HtmlDom( @"<html> <head><meta name='lockedDownAsShell' content='true'></meta></head> <body> <div id='bloomDataDiv'> <div data-book='copyright' lang='*'> Copyright © 2011, LASI & SILA </div> <div data-book='licenseUrl' lang='en'> http://creativecommons.org/licenses/by-nc-sa/4.0/ </div> </div> <div class='bloom-page cover frontCover outsideFrontCover coverColor bloom-frontMatter A4Landscape layout-style-Default' data-page='required singleton' data-export='front-matter-cover' id='2c97f5ad-24a1-47f0-8b5c-fa2181e1b129'> <div class='bloom-page cover frontCover outsideFrontCover coverColor bloom-frontMatter verso A4Landscape layout-style-Default' data-page='required singleton' data-export='front-matter-credits' id='7a220c97-07e4-47c5-835a-e37dc921f98f'> <div class='marginBox'> <div data-functiononhintclick='bookMetadataEditor' data-hint='Click to Edit Copyright & License' id='versoLicenseAndCopyright' class='bloom-metaData'> <div data-derived='copyright' lang='*' class='copyright'></div> <div data-derived='originalCopyrightAndLicense' lang='en' class='copyright'></div> </div> </div> </div> </div> </body> </html>" ); var metadata = BookCopyrightAndLicense.GetMetadata(dom); var initialCopyright = metadata.CopyrightNotice; Assert.AreEqual("Copyright © 2011, LASI & SILA", initialCopyright); var bookData = new BookData(dom, _collectionSettings, null); BookCopyrightAndLicense.SetOriginalCopyrightAndLicense(dom, bookData, _collectionSettings); var originalCopyright = GetEnglishOriginalCopyrightAndLicense(dom); Assert.AreEqual("Adapted from original, Copyright © 2011, LASI & SILA. Licensed under CC-BY-NC-SA 4.0.", originalCopyright); BookCopyrightAndLicense.UpdateDomFromDataDiv(dom, null, _collectionSettings); var nodes1 = dom.RawDom.SelectNodes("/html/body//div[@data-derived='originalCopyrightAndLicense']"); Assert.AreEqual(1, nodes1.Count); Assert.AreEqual("Adapted from original, Copyright © 2011, LASI & SILA. Licensed under CC-BY-NC-SA 4.0.", nodes1.Item(0).InnerText); Assert.AreEqual("Adapted from original, Copyright © 2011, LASI & SILA. Licensed under CC-BY-NC-SA 4.0.", nodes1.Item(0).InnerXml); var nodes2 = dom.RawDom.SelectNodes("/html/body//div[@data-derived='copyright']"); Assert.AreEqual(1, nodes2.Count); Assert.AreEqual("", nodes2.Item(0).InnerText); Assert.AreEqual("", nodes2.Item(0).InnerXml); AssertOriginalCopyrightAndLicense(dom, "Copyright © 2011, LASI & SILA", "http://creativecommons.org/licenses/by-nc-sa/4.0/"); }
public void SetMetadata_CopiesCopyrightAndOriginalCopyrightToMultipleDestinations() { // We could test other fields too, but these are enough to cover the two main methods that do the copying. var html = @"<html><head><meta name='lockedDownAsShell' content='true'></meta></head><body> <div id='bloomDataDiv'> <div data-book='copyright' lang='*'>Copyright © 2008, Bar Publishers</div> <div data-book='originalLicenseUrl' lang='*'>http://creativecommons.org/licenses/by-nc/4.0/</div> <div data-book='originalLicenseNotes' lang='*'>You can do anything you want if your name is Fred.</div> <div data-book='originalCopyright' lang='*'>Copyright © 2007, Foo Publishers</div> </div> <div id='test' class='test'> <div data-derived='copyright' lang='*'>something obsolete</div> <div data-derived='originalCopyrightAndLicense' lang='en'>BoilerPlateDescription</div> </div> <div id='test2' class='test'> <div data-derived='copyright' lang='*'>something else obsolete to be overwritten</div> <div data-derived='originalCopyrightAndLicense' lang='en'>Some other place we show original copyright</div> </div> </body></html>" ; var bookDom = new HtmlDom(html); var bookData = new BookData(bookDom, _collectionSettings, null); var metadata = BookCopyrightAndLicense.GetMetadata(bookDom, bookData); metadata.CopyrightNotice = "Copyright © 2019, Foo-Bar Publishers"; BookCopyrightAndLicense.SetMetadata(metadata, bookDom, "", bookData, false); // This is an abbreviated version of the text we expect in originalCopyrightAndLicense. Now that we have an embedded <cite> element, matching the whole thing // is difficult. We have other tests that deal with exactly what goes in this field; here we're just concerned with generating it or not. AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*' and contains(text(),'This book is an adaptation of the original')]", 2); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2019, Foo-Bar Publishers')]", 2); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='copyright' and contains(text(), 'Copyright © 2019, Foo-Bar Publishers')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalCopyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath("//div[@id='bloomDataDiv']/div[@data-book='licenseUrl']"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalLicenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1); // Change to use the original copyright and license. var originalMetadata = BookCopyrightAndLicense.GetOriginalMetadata(bookDom, bookData); BookCopyrightAndLicense.SetMetadata(originalMetadata, bookDom, "", bookData, true); AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*']"); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and .='']", 2); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2007, Foo Publishers')]", 2); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='copyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalCopyright' and contains(text(), 'Copyright © 2007, Foo Publishers')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='licenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1); AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='originalLicenseUrl' and contains(text(), 'http://creativecommons.org/licenses/by-nc/4.0/')]", 1); }
public void SetLicenseMetadata_ToNoLicenseUrl_OriginalHasLicenseUrlInEn_ClearsEn() { string dataDivContent = @"<div lang='en' data-book='licenseUrl'>http://creativecommons.org/licenses/by-nc-sa/3.0/</div>"; var dom = MakeDom(dataDivContent); var collectionSettings = new CollectionSettings(); var bookData = new BookData(dom, collectionSettings, null); var creativeCommonsLicense = (CreativeCommonsLicense)(BookCopyrightAndLicense.GetMetadata(dom, bookData).License); Assert.IsTrue(creativeCommonsLicense.AttributionRequired); // yes, we got a CC license from the 'en' licenseUrl var newLicense = new CustomLicense(); var newMetaData = new Metadata(); newMetaData.License = newLicense; BookCopyrightAndLicense.SetMetadata(newMetaData, dom, null, bookData, false); AssertThatXmlIn.Dom(dom.RawDom).HasNoMatchForXpath("//div[@data-book='licenseUrl']"); }
private static Metadata GetMetadata(string dataDivContent) { var dom = MakeDom(dataDivContent); return(BookCopyrightAndLicense.GetMetadata(dom)); }