Exemple #1
0
        public void UpdateDomFromDataDiv_CCLicense_OnPageTheLicenseHasFrench()
        {
            _collectionSettings.Language1Iso639Code = "fr";
            _collectionSettings.Language2Iso639Code = "en";

            //NB: ideally, this test would just set the licenseUrl and then test the resulting description.
            //That is, the description would not even be in the datadiv, since all we need is the licenseURl
            //(at least for creative commons licenses). We would then just generate the description when we
            //update the page.
            //However, for backwards compatibility, we still (as of 3.6) determine the description when doing
            //a SetMetadata, put the description in the bloomdatadiv, and then it just flows down
            //to the page.
            var html     = @"<html><body>
							<div id='bloomDataDiv'>
								<div data-book='licenseDescription' lang='es'>Spanish Description</div>
								<div data-book='licenseDescription' lang='fr'>French Description</div>
								<div data-book='licenseDescription' lang='en'>English Description</div>
							</div>
							<div id='test'>
								<div data-derived='licenseDescription' lang='en'>BoilerPlateDescription</div>
							</div>
						</body></html>"                        ;
            var bookDom  = new HtmlDom(html);
            var bookData = new BookData(bookDom, _collectionSettings, null);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", bookData, false);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='test']/*[@data-derived='licenseDescription' and @lang='fr' and contains(text(),'French')]", 1);
        }
Exemple #2
0
        public void UpdateDomFromDataDiv_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);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", _collectionSettings);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*' and contains(text(),'Adapted from original, Copyright © 2007, Foo Publishers. Licensed under CC-BY-NC 4.0. You can do anything you want if your name is Fred.')]", 2);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2008, Bar Publishers')]", 2);
        }
        public void UpdateDomFromDataDiv_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);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", _collectionSettings, 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 getting the right number of copies.
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='originalCopyrightAndLicense' and @lang='*' and contains(text(),'Adapted from original')]", 2);
            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@class='test']/*[@data-derived='copyright' and @lang='*' and contains(text(),'Copyright © 2008, Bar Publishers')]", 2);

            // Changing the useOriginalCopyright flag should empty out the data-derived='originalCopyrightAndLicense' divs.
            // The #bloomDataDiv would have to change to change the data-derived='copyright' divs.
            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", _collectionSettings, true);
            Console.WriteLine("DEBUG bookDom =\n{0}", bookDom.RawDom.OuterXml);
            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 © 2008, Bar Publishers')]", 2);
        }
Exemple #4
0
        /// <summary>
        /// Start out with an html with a bloomDataDiv describe by the parameters, then run it through the derivation of
        /// elements, then check to see that we got the expected result
        /// </summary>
        /// <param name="key">the data key. E.g. 'licenseDescription'</param>
        /// <param name="dataDivValue">if null, then the element should not be present at all in the bloomDataDiv of the incoming html</param>
        /// <param name="tag">defaults to div, for img we pass in "img"</param>
        /// <param name="valueAttribute"></param>
        /// <param name="lang1"></param>
        /// <param name="lang2"></param>
        /// <param name="lang3"></param>
        /// <param name="description"></param>
        private void CheckUpdateDomFromDataDiv(string key, string dataDivValue, string lang1 = "en", string lang2 = "", string lang3 = "", string description = null, string customXPath = null)
        {
            if (description == null)
            {
                description = string.Format("{0} should be '{1}'", key, dataDivValue);
            }

            _collectionSettings.Language1Iso639Code = lang1;
            _collectionSettings.Language2Iso639Code = lang2;
            _collectionSettings.Language3Iso639Code = lang3;

            var existingLicenseBlockOnPage = @"<div id='test'>
						<div data-derived = 'copyright' lang='en'>Some Copyright</div>
						<img src='license.png' alt='blah blah' data-derived='licenseImage'/>
						<div data-derived = 'licenseUrl' lang='en'>Boilerplate.com</div>
						<div data-derived='licenseDescription' lang='en'>BoilerPlateDescription</div>
						<div data-derived='licenseNotes' lang='en'>BoilerPlateNotes</div>
					</div>"                    ;

            string html = "<html><body><div id='bloomDataDiv'>";

            if (dataDivValue != null)             //we want this even if it is empty, just not null
            {
                html += string.Format("<{0} data-book='{1}' lang='en'>{2}</{0}>", "div", key, dataDivValue);
            }
            html += "</div>";            //end of datadiv
            html += existingLicenseBlockOnPage;
            html += "</body></html>";
            var bookDom  = new HtmlDom(html);
            var bookData = new BookData(bookDom, _collectionSettings, null);

            BookCopyrightAndLicense.UpdateDomFromDataDiv(bookDom, "", bookData, false);
            string valuePredicate;

            if (key == "licenseImage")
            {
                valuePredicate = string.IsNullOrEmpty(dataDivValue) ? "@src=''" : "@src='" + dataDivValue + "'";
            }
            else
            {
                valuePredicate = string.IsNullOrEmpty(dataDivValue) ? "(text()='' or not(text()))" : "text()='" + dataDivValue + "'";
            }
            var xpath = "//div[@id='test']/*[@data-derived='" + key + "' and " + valuePredicate + "]";

            if (!string.IsNullOrEmpty(customXPath))
            {
                xpath = customXPath;
            }
            try
            {
                AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath(xpath, 1);
            }
            catch (AssertionException)
            {
                Console.WriteLine("xpath was:" + xpath);
                Assert.Fail(description);
            }
        }
Exemple #5
0
        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 &amp; 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 &amp; 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 &amp; 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 &amp; SILA", "http://creativecommons.org/licenses/by-nc-sa/4.0/");
        }