public UpdateVariablesAndDataDivThroughDOM ( |
||
info | ||
Résultat | void |
public void UpdateVariablesAndDataDivThroughDOM_NewLangAdded_AddedToDataDiv() { var dom = new HtmlDom(@"<html><head></head><body><div data-book='someVariable' lang='en'>hi</div></body></html>"); var e = dom.RawDom.CreateElement("div"); e.SetAttribute("data-book", "someVariable"); e.SetAttribute("lang", "fr"); e.InnerText = "bonjour"; dom.RawDom.SelectSingleNode("//body").AppendChild(e); var data = new BookData(dom, new CollectionSettings(), null); data.UpdateVariablesAndDataDivThroughDOM(); AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//body/div[1][@id='bloomDataDiv']", 1);//NB microsoft uses 1 as the first. W3c uses 0. AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='someVariable' and @lang='en' and text()='hi']", 1); AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='someVariable' and @lang='fr' and text()='bonjour']", 1); }
public void UpdateVariablesAndDataDivThroughDOM_VariableIsNull_DataDivForItRemoved() { var htmlDom = new HtmlDom(); var data = new BookData(htmlDom, new CollectionSettings(), null); data.Set("1","one","en"); data.Set("1", null, "es"); data.UpdateVariablesAndDataDivThroughDOM(); AssertThatXmlIn.Dom(htmlDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/body/div/div[@lang='en']",1); AssertThatXmlIn.Dom(htmlDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("html/body/div/div[@lang='es']", 0); }
public void UpdateVariablesAndDataDivThroughDOM_HasDataLibraryValues_LibraryValuesNotPutInDataDiv() { var dom = new HtmlDom(@"<html><head></head><body><div data-book='someVariable' lang='en'>hi</div><div data-collection='user' lang='en'>john</div></body></html>"); var data = new BookData(dom, new CollectionSettings(), null); data.UpdateVariablesAndDataDivThroughDOM(); AssertThatXmlIn.Dom(dom.RawDom).HasNoMatchForXpath("//div[@id='bloomDataDiv']/div[@data-book='user']"); AssertThatXmlIn.Dom(dom.RawDom).HasNoMatchForXpath("//div[@id='bloomDataDiv']/div[@data-collection]"); }
public void UpdateVariablesAndDataDivThroughDOM_DoesNotExist_MakesOne() { var dom = new HtmlDom(@"<html><head></head><body><div data-book='someVariable'>world</div></body></html>"); var data = new BookData(dom, new CollectionSettings(), null); data.UpdateVariablesAndDataDivThroughDOM(); AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//body/div[1][@id='bloomDataDiv']", 1);//NB microsoft uses 1 as the first. W3c uses 0. AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='bloomDataDiv']/div[@data-book='someVariable' and text()='world']", 1); }
public void UpdateFieldsAndVariables_CustomLibraryVariable_CopiedToOtherElement() { var dom=new HtmlDom(@"<html ><head></head><body> <div class='bloom-page' id='guid3'> <p> <textarea lang='xyz' id='copyOfVTitle' data-book='bookTitle'>tree</textarea> <textarea lang='xyz' id='1' data-collection='testLibraryVariable'>aa</textarea> <textarea lang='xyz' id='2' data-collection='testLibraryVariable'>bb</textarea> </p> </div> </body></html>"); var data = new BookData(dom, _collectionSettings, null); data.UpdateVariablesAndDataDivThroughDOM(); var textarea2 = dom.SelectSingleNodeHonoringDefaultNS("//textarea[@id='2']"); Assert.AreEqual("aa", textarea2.InnerText); }
public void UpdateVariablesAndDataDivThroughDOM_DataBookAttributes_AttributesAddedToDiv() { var dom = new HtmlDom(@"<html><head></head><body> <div id='bloomDataDiv'> <div data-book-attributes='frontCover' data-backgroundaudio='audio/SoundTrack1.mp3' data-backgroundaudiovolume='0.17'></div> </div> <div id='firstPage' class='bloom-page' data-book-attributes='frontCover'>1st page</div> </body></html>"); var data = new BookData(dom, _collectionSettings, null); data.UpdateVariablesAndDataDivThroughDOM(); AssertThatXmlIn.Dom(dom.RawDom) .HasSpecifiedNumberOfMatchesForXpath("//div[@id='firstPage' and @data-book-attributes='frontCover' and @data-backgroundaudio='audio/SoundTrack1.mp3' and @data-backgroundaudiovolume='0.17']", 1); }
public void UpdateFieldsAndVariables_HasBookTitleTemplateWithVernacularPlaceholder_CreatesTitleForVernacular() { var dom = new HtmlDom(@"<html ><head></head><body> <div id='bloomDataDiv'> <div data-book='bookTitleTemplate' lang='{V}'>the title</div> </div> </body></html>"); var data = new BookData(dom, _collectionSettings, null); data.UpdateVariablesAndDataDivThroughDOM(); AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@data-book='bookTitle' and @lang='"+_collectionSettings.Language1Iso639Code+"' and text()='the title']",1); }