//Got this by pasting into the quiz page when the Talking Book was open // This fails. Enable when fixing BL-5910 /*[TestCase(@"<p><span id='b352ae2e-8394-4d6b-82a3-367521cbafb5' class='audio-sentence'>first <br></span> * <span id='b6376333-986a-4b23-91ea-31028e19da07' class='audio-sentence'>one <br></span> * <span id='i3636d82b-4d87-4b21-9a36-3b020a957abd' class='audio-sentence'>*two</span></p> * <p><span id='i7e03445c-1936-428d-8911-e829f55ae863' class='audio-sentence'>second <br></span> * <span id='i2b681f7e-a315-4584-8524-0f4809c3bf18' class='audio-sentence'>*aa <br></span> * <span id='i34524d36-0a96-4788-8131-991bd855bb77' class='audio-sentence'>bb <br> <br></span></p>")] */ public void ExtractQuestionGroups_ParsesCorrectly(string contents) { contents = contents.Replace("<br>", "<br/>"); // convert from html to xml var page = new XmlDocument(); page.LoadXml(@"<div><div class='bloom-editable' lang='abc'>" + contents + "</div></div>"); var questionGroups = new List <QuestionGroup>(); BloomReaderFileMaker.ExtractQuestionGroups(page.DocumentElement, questionGroups); Assert.AreEqual(1, questionGroups.Count); Assert.AreEqual(2, questionGroups[0].questions.Length); Assert.AreEqual("first", questionGroups[0].questions[0].question); Assert.AreEqual(2, questionGroups[0].questions[0].answers.Length); Assert.AreEqual("one", questionGroups[0].questions[0].answers[0].text); Assert.AreEqual("two", questionGroups[0].questions[0].answers[1].text); Assert.IsFalse(questionGroups[0].questions[0].answers[0].correct); Assert.IsTrue(questionGroups[0].questions[0].answers[1].correct); Assert.AreEqual("second", questionGroups[0].questions[1].question); Assert.AreEqual(2, questionGroups[0].questions[1].answers.Length); Assert.AreEqual("aa", questionGroups[0].questions[1].answers[0].text); Assert.AreEqual("bb", questionGroups[0].questions[1].answers[1].text); Assert.IsTrue(questionGroups[0].questions[1].answers[0].correct); Assert.IsFalse(questionGroups[0].questions[1].answers[1].correct); }
public void ExtractQuestionGroups_Long_ParsesCorrectly(string contents) { var page = new XmlDocument(); page.LoadXml(@"<div><div class='bloom-editable' lang='abc'>" + contents + "</div></div>"); var questionGroups = new List <QuestionGroup>(); BloomReaderFileMaker.ExtractQuestionGroups(page.DocumentElement, questionGroups); Assert.AreEqual(1, questionGroups.Count); Assert.AreEqual(4, questionGroups[0].questions.Length); }
public void EmbedFonts_EmbedsExpectedFontsAndReportsOthers() { var bookHtml = @"<html><head> <link rel='stylesheet' href='Basic Book.css' type='text/css'></link> <link rel='stylesheet' href='Traditional-XMatter.css' type='text/css'></link> <link rel='stylesheet' href='CustomBookStyles.css' type='text/css'></link> <style type='text/css' title='userModifiedStyles'> /*<![CDATA[*/ .Times-style[lang='tpi'] { font-family: Times New Roman ! important; font-size: 12pt } /*]]>*/ </style> </head><body> <div class='bloom-page' id='guid1'></div> </body></html>" ; var testBook = CreateBookWithPhysicalFile(bookHtml, bringBookUpToDate: false); var fontFileFinder = new StubFontFinder(); using (var tempFontFolder = new TemporaryFolder("EmbedFonts_EmbedsExpectedFontsAndReportsOthers")) { fontFileFinder.NoteFontsWeCantInstall = true; // Font called for in HTML var timesNewRomanFileName = "Times New Roman R.ttf"; var tnrPath = Path.Combine(tempFontFolder.Path, timesNewRomanFileName); File.WriteAllText(tnrPath, "This is phony TNR"); // Font called for in custom styles CSS var calibreFileName = "Calibre R.ttf"; var calibrePath = Path.Combine(tempFontFolder.Path, calibreFileName); File.WriteAllBytes(calibrePath, new byte[200008]); // we want something with a size greater than zero in megs fontFileFinder.FilesForFont["Times New Roman"] = new[] { tnrPath }; fontFileFinder.FilesForFont["Calibre"] = new [] { calibrePath }; fontFileFinder.FontsWeCantInstall.Add("NotAllowed"); // And "NotFound" just doesn't get a mention anywhere. var stubProgress = new StubProgress(); var customStylesPath = Path.Combine(testBook.FolderPath, "CustomBookStyles.css"); File.WriteAllText(customStylesPath, ".someStyle {font-family:Calibre} .otherStyle {font-family: NotFound} .yetAnother {font-family:NotAllowed}"); var tnrGroup = new FontGroup(); tnrGroup.Normal = tnrPath; fontFileFinder.FontGroups["Times New Roman"] = tnrGroup; var calibreGroup = new FontGroup(); calibreGroup.Normal = calibrePath; fontFileFinder.FontGroups["Calibre"] = calibreGroup; BloomReaderFileMaker.EmbedFonts(testBook, stubProgress, fontFileFinder); Assert.That(File.Exists(Path.Combine(testBook.FolderPath, timesNewRomanFileName))); Assert.That(File.Exists(Path.Combine(testBook.FolderPath, calibreFileName))); Assert.That(stubProgress.MessagesNotLocalized, Has.Member("Checking Times New Roman font: License OK for embedding.")); Assert.That(stubProgress.MessagesNotLocalized, Has.Member("<span style='color:blue'>Embedding font Times New Roman at a cost of 0.0 megs</span>")); Assert.That(stubProgress.MessagesNotLocalized, Has.Member("Checking Calibre font: License OK for embedding.")); Assert.That(stubProgress.MessagesNotLocalized, Has.Member("<span style='color:blue'>Embedding font Calibre at a cost of 0.2 megs</span>")); Assert.That(stubProgress.ErrorsNotLocalized, Has.Member("Checking NotAllowed font: License does not permit embedding.")); Assert.That(stubProgress.ErrorsNotLocalized, Has.Member("Substituting \"Andika New Basic\" for \"NotAllowed\"")); Assert.That(stubProgress.ErrorsNotLocalized, Has.Member("Checking NotFound font: No font found to embed.")); Assert.That(stubProgress.ErrorsNotLocalized, Has.Member("Substituting \"Andika New Basic\" for \"NotFound\"")); var fontSourceRulesPath = Path.Combine(testBook.FolderPath, "fonts.css"); var fontSource = RobustFile.ReadAllText(fontSourceRulesPath); // We're OK with these in either order. string lineTimes = "@font-face {font-family:'Times New Roman'; font-weight:normal; font-style:normal; src:url(Times New Roman R.ttf) format('opentype');}" + Environment.NewLine; string lineCalibre = "@font-face {font-family:'Calibre'; font-weight:normal; font-style:normal; src:url(Calibre R.ttf) format('opentype');}" + Environment.NewLine; Assert.That(fontSource, Is.EqualTo(lineTimes + lineCalibre).Or.EqualTo(lineCalibre + lineTimes)); AssertThatXmlIn.Dom(testBook.RawDom).HasSpecifiedNumberOfMatchesForXpath("//link[@href='fonts.css']", 1); } }