Beispiel #1
0
        protected void CheckBasicsInPage(params string[] images)
        {
            AssertThatXmlIn.String(_page1Data).HasNoMatchForXpath("//*[@aria-describedby and not(@id)]");
            // Not sure why we sometimes have these, but validator doesn't like them.
            AssertThatXmlIn.String(_page1Data).HasNoMatchForXpath("//*[@lang='']");
            AssertThatXmlIn.String(_page1Data).HasNoMatchForXpath("//xhtml:script", _ns);
            AssertThatXmlIn.String(_page1Data).HasNoMatchForXpath("//*[@lang='*']");
            AssertThatXmlIn.String(_page1Data).HasNoMatchForXpath("//xhtml:div[@contenteditable]", _ns);

            foreach (var image in images)
            {
                AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//img[@src='" + kImagesSlash + image + ".png']");
            }
            AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//xhtml:link[@rel='stylesheet' and @href='" + kCssSlash + "defaultLangStyles.css']", _ns);
            AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//xhtml:link[@rel='stylesheet' and @href='" + kCssSlash + "customCollectionStyles.css']", _ns);
            AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//xhtml:link[@rel='stylesheet' and @href='" + kCssSlash + "customBookStyles.css']", _ns);
            AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//xhtml:link[@rel='stylesheet' and @href='" + kCssSlash + "fonts.css']", _ns);

            AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//xhtml:body/*[@role]", _ns);
            AssertThatXmlIn.String(_page1Data).HasAtLeastOneMatchForXpath("//xhtml:body/*[@aria-label]", _ns);
        }
        public void HtmlWithNoReleaseNotesElementIsCompletelyReplaced()
        {
            var testMarkdown = new GenerateReleaseArtifacts();

            using (
                var filesForTest = new TwoTempFilesForTest(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".Test.md"),
                                                           Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".Test.htm")))
            {
                var markdownFile = filesForTest.FirstFile;
                var htmlFile     = filesForTest.SecondFile;
                File.WriteAllLines(markdownFile,
                                   new[]
                                   { "## 2.3.9", "* with some random content", "* does some things", "## 2.3.7", "* more", "## 2.2.2", "* things" });
                File.WriteAllLines(htmlFile,
                                   new[] { "<html>", "<body>", "<div class='notmarkdown'/>", "</body>", "</html>" });
                testMarkdown.MarkdownFile = markdownFile;
                testMarkdown.HtmlFile     = htmlFile;
                Assert.That(testMarkdown.CreateHtmFromMarkdownFile(), Is.True);
                AssertThatXmlIn.File(htmlFile).HasNoMatchForXpath("//div[@notmarkdown]");
            }
        }
        public void Run_MultipleWritingSystemsInLexicalUnit_PicksMoreFrequentOne()
        {
            MergeTwoAndTest(
                @"<entry id='foo' GUID1 dateModified='2006-10-02T01:42:57Z'>
					<lexical-unit>
						  <form lang='de'><text>fooLess</text></form>
						   <form lang='pt'><text>fooMore</text></form>
					</lexical-unit>
				</entry>"                ,
                @"<entry GUID2 dateModified='2009-10-02T01:42:57Z'>
					<lexical-unit>
						   <form lang='pt'><text>fooMore</text></form>
					</lexical-unit>
				</entry>"                ,
                () =>
            {
                AssertThatXmlIn.Dom(_resultDom).HasSpecifiedNumberOfMatchesForXpath("//entry", 1);
                AssertThatXmlIn.Dom(_resultDom).HasSpecifiedNumberOfMatchesForXpath(
                    "//entry/lexical-unit/form", 2);
            });
        }
        public void Run_HasIncompatibleFieldsAtEntryLevel_NotMerged()
        {
            MergeTwoAndTest(
                @"<entry id='foo' GUID1 dateModified='2006-10-02T01:42:57Z'>
					<lexical-unit>
						  <form lang='etr'><text>foo</text></form>
					</lexical-unit>

					<field type='Plural'><form lang='seh'><text>xxxx</text></form></field>
				</entry>"                ,
                @"<entry GUID2 dateModified='2009-10-02T01:42:57Z'>
					<lexical-unit>
						  <form lang='etr'><text>foo</text></form>
					</lexical-unit>
					 <field type='Plural'><form lang='seh'><text>yyy</text></form></field>
				</entry>"                ,
                () =>
            {
                AssertThatXmlIn.Dom(_resultDom).HasSpecifiedNumberOfMatchesForXpath("//entry", 2);
            });
        }
Beispiel #5
0
        public void EntryMakeItToPLift()
        {
            var xmlOfEntries = @" <entry id='foo1'>
										<lexical-unit><form lang='qaa-x-qaa'><text>hello</text></form></lexical-unit>
								 </entry>"                                ;

            using (var p = new WeSay.Project.Tests.ProjectDirectorySetupForTesting(xmlOfEntries))
            {
                PLiftMaker maker = new PLiftMaker();
                using (var project = p.CreateLoadedProject())
                {
                    using (var repository = project.GetLexEntryRepository())
                    {
                        string outputPath = Path.Combine(project.PathToExportDirectory, project.Name + ".xhtml");
                        maker.MakePLiftTempFile(outputPath, repository, project.DefaultPrintingTemplate, LiftWriter.ByteOrderStyle.BOM);
                        AssertThatXmlIn.File(outputPath).
                        HasAtLeastOneMatchForXpath("//field[@type='headword']/form[@lang='qaa-x-qaa']/text[text()='hello']");
                    }
                }
            }
        }
Beispiel #6
0
 public void MigrateIfNeeded_ConfigFileContainsWritingSystemIdThatIsMigrated_WritingSystemIdIsChanged()
 {
     using (var e = new TestEnvironment())
     {
         e.WriteToPrefsFile(WritingSystemPrefsFileContent.TwoWritingSystems("bogusws1", "bogusws2"));
         var migrator = new WritingSystemsMigrator(e.ProjectPath);
         migrator.MigrateIfNecessary();
         AssertThatXmlIn.File(e.PathToConfigFile).HasAtLeastOneMatchForXpath(
             "/configuration/components/viewTemplate/fields/field/writingSystems/id[1][text()='qaa-x-bogusws1']"
             );
         AssertThatXmlIn.File(e.PathToConfigFile).HasAtLeastOneMatchForXpath(
             "/configuration/components/viewTemplate/fields/field/writingSystems/id[2][text()='qaa-x-bogusws2']"
             );
         AssertThatXmlIn.File(e.PathToConfigFile).HasAtLeastOneMatchForXpath(
             "/configuration/tasks/task/writingSystemsToMatch[text()='qaa-x-bogusws1, qaa-x-bogusws2']"
             );
         AssertThatXmlIn.File(e.PathToConfigFile).HasAtLeastOneMatchForXpath(
             "/configuration/tasks/task/writingSystemsWhichAreRequired[text()='qaa-x-bogusws1, qaa-x-bogusws2']"
             );
     }
 }
Beispiel #7
0
        public void DefaultBookshelf_ReadWrite()
        {
            var bloomCollectionFileContents =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<Collection version=""0.2"">
	<DefaultBookTags>bookshelf:kygyzstan2020-ky-grade1-term1</DefaultBookTags>
</Collection>";
            const string collectionName = "test";
            var          collectionPath = CollectionSettings.GetPathForNewSettings(_folder.Path, collectionName);

            Directory.CreateDirectory(Path.GetDirectoryName(collectionPath));
            RobustFile.WriteAllText(collectionPath, bloomCollectionFileContents);
            var settings = CreateCollectionSettings(_folder.Path, collectionName);

            Assert.That(settings.DefaultBookshelf, Is.EqualTo("kygyzstan2020-ky-grade1-term1"));
            settings.DefaultBookshelf = "some-other-shelf";
            settings.Save();
            var newContents = RobustFile.ReadAllText(collectionPath);

            AssertThatXmlIn.String(newContents).HasSpecifiedNumberOfMatchesForXpath("//DefaultBookTags[text()='bookshelf:some-other-shelf']", 1);
        }
Beispiel #8
0
 public void RangeSectionMergedCorrectly()
 {
     using (var oursTemp = new TempFile(_ours))
         using (var theirsTemp = new TempFile(_theirs))
             using (var ancestorTemp = new TempFile(_ancestor))
             {
                 var listener   = new ListenerForUnitTests();
                 var situation  = new NullMergeSituation();
                 var mergeOrder = new MergeOrder(oursTemp.Path, ancestorTemp.Path, theirsTemp.Path, situation)
                 {
                     EventListener = listener
                 };
                 XmlMergeService.Do3WayMerge(mergeOrder, new LiftEntryMergingStrategy(mergeOrder),
                                             false,
                                             "header",
                                             "entry", "guid");
                 var result = File.ReadAllText(mergeOrder.pathToOurs);
                 XmlTestHelper.AssertXPathMatchesExactlyOne(result, "lift/entry[@id='usOnly']");
                 AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(@"lift/header/ranges/range", 4);
             }
 }
Beispiel #9
0
        public void MigrateJustPicture_CopiesImage()
        {
            SetDom(@"<div class='bloom-page' data-pagelineage='5dcd48df-e9ab-4a07-afd4-6a24d0398385' id='thePage'>
			   <div class='marginBox'>
					<div class='bloom-imageContainer bloom-leadingElement'><img data-license='cc-by-nc-sa' data-copyright='Copyright © 2012, LASI' style='width: 608px; height: 471px; margin-left: 199px; margin-top: 0px;' src='erjwx3bl.q3c.png' alt='This picture, erjwx3bl.q3c.png, is missing or was loading too slowly.' height='471' width='608'></img></div>
				</div>
			</div>
			"            );
            var book = CreateBook();
            var dom  = book.RawDom;
            var page = (XmlElement)dom.SafeSelectNodes("//div[@id='thePage']")[0];

            book.BringPageUpToDate(page);

            var newPage = (XmlElement)dom.SafeSelectNodes("//div[@id='thePage']")[0];

            CheckPageIsCustomizable(newPage);
            CheckPageLineage(page, newPage, "5dcd48df-e9ab-4a07-afd4-6a24d0398385", "adcd48df-e9ab-4a07-afd4-6a24d0398385");
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//img[@data-license='cc-by-nc-sa' and @data-copyright='Copyright © 2012, LASI' and @src='erjwx3bl.q3c.png']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//img", 1);
        }
Beispiel #10
0
        public void MigrateIfNecessary_WsPrefsFileContainsWsContainingIsAudioIsTrueAndrfcTagAlreadyHasScript_ScriptContainsZxxxAndVariantContainsXDashAudioDashScript()
        {
            using (var environment = new TestEnvironment())
            {
                const string language = "en-Latn";
                const bool   isAudio  = true;
                environment.WriteContentToWsPrefsFile(WritingSystemPrefsFileContent.SingleWritingSystem(language, "",
                                                                                                        "", "", "", 0, false, "", "", true, isAudio)
                                                      );
                var migrator = new WritingSystemPrefsMigrator(
                    environment.WsPrefsFilePath,
                    environment.ChangeRfcTags);
                migrator.MigrateIfNecassary();
                string pathToEnFile = environment.GetFileForOriginalRfcTag(language);

                AssertThatXmlIn.File(pathToEnFile).HasAtLeastOneMatchForXpath("/ldml/identity/language[@type = 'en-Latn']");
                AssertThatXmlIn.File(pathToEnFile).HasAtLeastOneMatchForXpath("/ldml/identity/script[@type = 'Zxxx']");
                AssertThatXmlIn.File(pathToEnFile).HasNoMatchForXpath("/ldml/identity/region");
                AssertThatXmlIn.File(pathToEnFile).HasAtLeastOneMatchForXpath("/ldml/identity/variant[@type = 'x-audio']");
            }
        }
Beispiel #11
0
        public void PresetIsApp_StylesheetAreRelativePaths()
        {
            var code = HydrateBookCommand.Handle(new HydrateParameters()
            {
                Path              = _bookFolder.FolderPath,
                Preset            = "app",
                VernacularIsoCode = "en"
            });

            Assert.AreEqual(0, code, "Should return an exit code of 0, meaning it is happy.");
            Debug.Write(File.ReadAllText(_eventualHtmlPath));
            var dom = XmlHtmlConverter.GetXmlDomFromHtml(File.ReadAllText(_eventualHtmlPath));

            AssertThatXmlIn.Dom(dom)
            .HasSpecifiedNumberOfMatchesForXpath("//link[@href='basePage.css']", 1);

            AssertThatXmlIn.Dom(dom)
            .HasSpecifiedNumberOfMatchesForXpath("//link[@href='languageDisplay.css']", 1);
            AssertThatXmlIn.Dom(dom)
            .HasSpecifiedNumberOfMatchesForXpath("//link[@href='Video-XMatter.css']", 1);
        }
        public void PrepareDataBookTranslationGroups_PlaceholdersCreatedAsNeeded()
        {
            var contents = @"<html><body><div class='bloom-page'>
								<div class='bloom-translationGroup'>
										<div class='bloom-editable' data-book='bookTitle' lang='en'>Some English</div>
								</div>
						</div></body></html>"                        ;
            var dom      = new XmlDocument();

            dom.LoadXml(contents);

            var languages = new string[] { "en", "es", "fr" };

            TranslationGroupManager.PrepareDataBookTranslationGroups((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], languages);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable')]", 3);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es']", 1);
            //should touch the existing one
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='en' and text()='Some English']", 1);
        }
Beispiel #13
0
        private static void AssertHasAtLeastOneMatch(string xml, string xpath)
        {
            AssertThatXmlIn.String(xml).
            HasAtLeastOneMatchForXpath(xpath);

//
//            XmlDocument doc = GetDoc(xml);
//            XmlNode node = doc.SelectSingleNode(xpath);
//            if (node == null)
//            {
//                Console.WriteLine("Could not match "+xpath);
//                Console.WriteLine();
//                XmlWriterSettings settings = new XmlWriterSettings();
//                settings.Indent = true;
//                settings.ConformanceLevel = ConformanceLevel.Fragment;
//                XmlWriter writer = XmlWriter.Create(Console.Out, settings);
//                doc.WriteContentTo(writer);
//                writer.Flush();
//            }
//            Assert.IsNotNull(node);
        }
        public void UpdateContentLanguageClasses_BilingualContentPage_TurnsOnCorrectLanguages()
        {
            var contents = @"<html><body><div class='bloom-page' >
						<div class='bloom-translationGroup'>
							<div class='bloom-editable' lang='xyz'></div>
							<div class='bloom-editable' lang='en'></div>
							<div class='bloom-editable' lang='fr'></div>
							<div class='bloom-editable' lang='es'></div>
							</div>
						</div></body></html>"                        ;
            var dom      = new XmlDocument();

            dom.LoadXml(contents);
            var bookData = new BookData(new HtmlDom(dom), _collectionSettings, null);
            var pageDiv  = (XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0];

            TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, bookData, "xyz", /* makes bilingual --> */ "fr", "");
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'bloom-visibility-code-on')]", 2);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr' and contains(@class, 'bloom-visibility-code-on')]", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz' and contains(@class, 'bloom-visibility-code-on')]", 1);
        }
        public void CompressBookForDevice_PointsAtDeviceXMatter()
        {
            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>
					</head><body>
					<div class='bloom-page' id='guid1'></div>
			</body></html>"            ;

            TestHtmlAfterCompression(bookHtml,
                                     assertionsOnResultingHtmlString: html =>
            {
                var htmlDom = XmlHtmlConverter.GetXmlDomFromHtml(html);
                AssertThatXmlIn.Dom(htmlDom)
                .HasSpecifiedNumberOfMatchesForXpath(
                    "//html/head/link[@rel='stylesheet' and @href='Device-XMatter.css' and @type='text/css']", 1);
                AssertThatXmlIn.Dom(htmlDom)
                .HasNoMatchForXpath(
                    "//html/head/link[@rel='stylesheet' and @href='Traditional-XMatter.css' and @type='text/css']");
            });
        }
Beispiel #16
0
        public void MigrateIfNecessary_WsPrefsFileContainsWsContainingCustomSimpleSortRules_CustomSortRulesAreInLdml()
        {
            using (var environment = new TestEnvironment())
            {
                const string sortUsing = "CustomSimple";
                const string sortRules =
                    @"N n
O o";
                environment.WriteContentToWsPrefsFile(WritingSystemPrefsFileContent.SingleWritingSystem("en", "", sortUsing, sortRules, "", 0, false, "", "", true, false)
                                                      );
                var migrator = new WritingSystemPrefsMigrator(
                    environment.WsPrefsFilePath,
                    environment.ChangeRfcTags);
                migrator.MigrateIfNecassary();
                string pathToEnFile = environment.GetFileForOriginalRfcTag("en");
                AssertThatXmlIn.File(pathToEnFile).HasAtLeastOneMatchForXpath(
                    String.Format("/ldml/collations/collation/special/palaso:sortRulesType[@value='{0}']", sortUsing), environment.NamespaceManager
                    );
                AssertThatXmlIn.File(pathToEnFile).HasAtLeastOneMatchForXpath("/ldml/collations/collation/rules/p[text()='N'] ");                 //Only checking one character. Hopefully this means the rest are there too.
            }
        }
Beispiel #17
0
        public void TwoVariants()
        {
            LexEntry e    = MakeSimpleEntry();
            string   xml1 =
                @"
				 <variant>
					<form lang='und-fonipa'><text>boo</text></form>
				  </variant>"                ;
            String xml2 =
                @"<variant>
					<form lang='und-fonipa'><text>baa</text></form>
				  </variant>"                ;

            _builder.MergeInVariant(e, MakeBasicLiftMultiText(), xml1);
            _builder.MergeInVariant(e, MakeBasicLiftMultiText(), xml2);
            _builder.FinishEntry(e);
            _liftWriter.Add(e);
            _liftWriter.End();
            AssertThatXmlIn.String(_stringBuilder.ToString()).HasSpecifiedNumberOfMatchesForXpath("//entry/variant/form/text[text()='baa']", 1);
            AssertThatXmlIn.String(_stringBuilder.ToString()).HasSpecifiedNumberOfMatchesForXpath("//entry/variant/form/text[text()='boo']", 1);
        }
        public void Run_Has1NonCAWLSense_DoesNothing()
        {
            Run(
                @"<entry id='foo' guid='5e67f88d-f0f0-42d1-a10e-6a7abaac05a4'>
						<lexical-unit>
			<form
				lang='abc'>
				<text>ai</text>
			</form>
		</lexical-unit>
		<sense
			id='eye_5e67f88d-f0f0-42d1-a10e-6a7abaac05a4'>
			<grammatical-info
				value='Noun' />
			<gloss
				lang='en'>
				<text>eye</text>
			</gloss>
			<gloss
				lang='fr'>
				<text>œil</text>
			</gloss>
			<definition>
				<form
					lang='en'>
					<text>eye</text>
				</form>
				<form
					lang='fr'>
					<text>œil</text>
				</form>
			</definition>
		</sense>
				</entry>"                ,
                () =>
            {
                AssertThatXmlIn.Dom(_resultDom).HasSpecifiedNumberOfMatchesForXpath("//entry", 1);
                AssertThatXmlIn.Dom(_resultDom).HasSpecifiedNumberOfMatchesForXpath("//sense", 1);
            });
        }
        protected void CheckBasicsInManifest(params string[] imageFiles)
        {
            VerifyThatFilesInManifestArePresent();
            var assertThatManifest = AssertThatXmlIn.String(FixContentForXPathValueSlash(_manifestContent));

            assertThatManifest.HasAtLeastOneMatchForXpath("package[@version='3.0']");
            assertThatManifest.HasAtLeastOneMatchForXpath("package[@unique-identifier]");
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/dc:title", _ns);
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/dc:language", _ns);
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/dc:identifier", _ns);
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/dc:source", _ns);
            assertThatManifest.HasAtLeastOneMatchForXpath("package/metadata/meta[@property='dcterms:modified']");
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/opf:meta[@property='schema:accessMode']", _ns);
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/opf:meta[@property='schema:accessModeSufficient']", _ns);
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/opf:meta[@property='schema:accessibilityFeature']", _ns);
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/opf:meta[@property='schema:accessibilityHazard']", _ns);
            assertThatManifest.HasAtLeastOneMatchForXpath("opf:package/opf:metadata/opf:meta[@property='schema:accessibilitySummary']", _ns);

            // This is not absolutely required, but it's true for all our test cases and the way we generate books.
            assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@id='f1' and @href='1.xhtml']");
            // And that one page must be in the spine
            assertThatManifest.HasAtLeastOneMatchForXpath("package/spine/itemref[@idref='f1']");
            assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@properties='nav']");
            assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@properties='cover-image']");

            assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@id='defaultLangStyles' and @href='" + kCssSlash + "defaultLangStyles.css']");
            assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@id='customCollectionStyles' and @href='" + kCssSlash + "customCollectionStyles.css']");
            assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@id='customBookStyles' and @href='" + kCssSlash + "customBookStyles.css']");

            assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@id='AndikaNewBasic-R' and @href='" + kFontsSlash + "AndikaNewBasic-R.ttf' and @media-type='application^slash^vnd.ms-opentype']");
            // This used to be a test that it DOES include the bold (along with italic and BI) variants. But we decided not to...see BL-4202 and comments in EpubMaker.EmbedFonts().
            // So this is now a negative to check that they don't creep back in (unless we change our minds).
            assertThatManifest.HasNoMatchForXpath("package/manifest/item[@id='AndikaNewBasic-B' and @href='" + kFontsSlash + "AndikaNewBasic-B.ttf' and @media-type='application^slash^vnd.ms-opentype']");
            assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@id='fonts' and @href='" + kCssSlash + "fonts.css']");

            foreach (var image in imageFiles)
            {
                assertThatManifest.HasAtLeastOneMatchForXpath("package/manifest/item[@id='" + image + "' and @href='" + EpubMaker.kImagesFolder + "^slash^" + image + ".png']");
            }
        }
Beispiel #20
0
        public void MergeUserModifiedStyles_NewStyleHasLangAttr_Ignored()
        {
            var bookDom = new HtmlDom(
                @"<html>
					<head>
						<style type='text/css' title='userModifiedStyles'>
							.MyTest-style { font-size: ginormous; }</style>
					</head>
					<body>
						<div class='MyTest-style bogus'></div>
					</body>
				</html>"                );
            var pageDom = new XmlDocument();

            pageDom.LoadXml(@"<html>
				<head>
					<style type='text/css' title='userModifiedStyles'>
						.MyTest-style[lang='en'] { font-size: smaller; }
					</style>
				</head>
				<body>
					<div class='MyTest-style bogus'></div>
				</body>
			</html>"            );

            var pageStyleNode = pageDom.SelectSingleNode("//style");
            var bookStyleNode = HtmlDom.GetUserModifiedStyleElement(bookDom.Head);

            // SUT
            bookStyleNode.InnerText = HtmlDom.MergeUserStylesOnInsertion(bookStyleNode, pageStyleNode);

            var xpath = string.Format(StylesContainsXpath, "font-size: ginormous;");

            AssertThatXmlIn.Dom(bookDom.RawDom).HasSpecifiedNumberOfMatchesForXpath(xpath, 1);
            var xpath2 = "//style[@title=\"userModifiedStyles\" and contains(text(),\".MyTest-style[lang='en'] { font-size: smaller;\")]";

            AssertThatXmlIn.Dom(bookDom.RawDom).HasNoMatchForXpath(xpath2);
            VerifyUserStylesCdataWrapping(bookDom.RawDom);
        }
Beispiel #21
0
        public void MigrateUserConfig_WithV1_DoesMigrate()
        {
            string v1 =
                @"<?xml version='1.0' encoding='utf-8'?>
<configuration version='1'>
  <uiOptions>
	<language>wesay-th</language>
	<labelFontName>Segoe UI</labelFontName>
	<labelFontSizeInPoints>9</labelFontSizeInPoints>
  </uiOptions>
</configuration>
".Replace("'", "\"");

            using (var e = new EnvironmentForTests("ConfigToolMigrationTests"))
            {
                e.CreateDefaultProject();
                e.WriteUserConfig(v1);
                new WeSayWordsProject();
                WeSayWordsProject.Project.LoadFromProjectDirectoryPath(e.Path);
                AssertThatXmlIn.File(e.GetUserConfigFilePath()).HasAtLeastOneMatchForXpath("configuration[@version='2']");
            }
        }
        public void PrepareElementsInPageOrDocument_TranslationGroupHasPlaceHolder_PlaceholderCopiedToNewChildren()
        {
            var contents = @"<html><body><div class='bloom-page  bloom-trilingual'>
								<div class='bloom-translationGroup normal-style' data-placeholder='copy me' >
								</div>
						</div></body></html>"                        ;
            var dom      = new XmlDocument();

            dom.LoadXml(contents);
            var bookData = new BookData(new HtmlDom(dom), _collectionSettings, null);

            bookData.SetMultilingualContentLanguages("xyz", "fr", "es");

            TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], bookData);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @contenteditable='true' ]", 3);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'normal-style') and contains(@class, 'bloom-editable')]", 3);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[contains(@class, 'normal-style') and contains(@class, 'bloom-translationGroup')]", 0);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz' and @data-placeholder='copy me']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr' and @data-placeholder='copy me']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es' and @data-placeholder='copy me']", 1);
        }
Beispiel #23
0
        public void MigrateIfNecessary_LdmlForWritingSystemInWsPrefsFileAlreadyExists_LdmlIsUntouched()
        {
            using (var environment = new TestEnvironment())
            {
                environment.WriteContentToWsPrefsFile(WritingSystemPrefsFileContent.SingleWritingSystemForLanguage("en"));

                var ws = WritingSystemDefinition.Parse("en");
                ws.Abbreviation = "untouched";
                var wsRepo = environment.WritingSystems;
                wsRepo.Set(ws);
                wsRepo.Save();

                var migrator = new WritingSystemPrefsMigrator(
                    environment.WsPrefsFilePath,
                    environment.ChangeRfcTags);
                migrator.MigrateIfNecassary();

                AssertThatXmlIn.File(environment.GetFileForOriginalRfcTag("en")).HasAtLeastOneMatchForXpath(
                    "/ldml/special/palaso:abbreviation[@value='untouched']",
                    environment.NamespaceManager);
            }
        }
        public void GenerateXHTMLForEntry_ReversalStringGeneratesContent()
        {
            var formNode = new ConfigurableDictionaryNode
            {
                FieldDescription      = "ReversalForm",
                Label                 = "Form",
                DictionaryNodeOptions = new DictionaryNodeWritingSystemOptions
                {
                    WsType  = DictionaryNodeWritingSystemOptions.WritingSystemType.Reversal,
                    Options = new List <DictionaryNodeListOptions.DictionaryNodeOption>
                    {
                        new DictionaryNodeListOptions.DictionaryNodeOption {
                            Id = "fr"
                        }
                    },
                    DisplayWritingSystemAbbreviations = false
                }
            };
            var reversalNode = new ConfigurableDictionaryNode
            {
                Children = new List <ConfigurableDictionaryNode> {
                    formNode
                },
                FieldDescription = "ReversalIndexEntry"
            };

            CssGeneratorTests.PopulateFieldsForTesting(reversalNode);
            var rie           = CreateInterestingFrenchReversalEntry();
            var entryHeadWord = rie.ReferringSenses.First().Entry.HeadWord;

            //SUT
            var result = ConfiguredXHTMLGenerator.GenerateXHTMLForEntry(rie, reversalNode, null, DefaultSettings);
            var reversalFormDataPath = string.Format("/div[@class='reversalindexentry']/span[@class='reversalform']/span[text()='{0}']",
                                                     TsStringUtils.Compose(rie.LongName));
            var entryDataPath = string.Format("//span[text()='{0}']", entryHeadWord.get_NormalizedForm(FwNormalizationMode.knmNFC).Text);

            AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(reversalFormDataPath, 1);
            AssertThatXmlIn.String(result).HasNoMatchForXpath(entryDataPath);
        }
Beispiel #25
0
        public void Save_WritingSystemIdConflated_ChangeLogUpdatedAndDoesNotContainDelete()
        {
            using (var e = new TestEnvironment())
            {
                var repo = LdmlInFolderWritingSystemRepository.Initialize(Path.Combine(e.TestPath, "idchangedtest1"), DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);
                var ws   = WritingSystemDefinition.Parse("en");
                repo.Set(ws);
                repo.Save();

                var ws2 = WritingSystemDefinition.Parse("de");
                repo.Set(ws2);
                repo.Save();

                repo.Conflate(ws.Id, ws2.Id);
                repo.Save();

                string logFilePath = Path.Combine(repo.PathToWritingSystems, "idchangelog.xml");
                AssertThatXmlIn.File(logFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/From[text()='en']");
                AssertThatXmlIn.File(logFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/To[text()='de']");
                AssertThatXmlIn.File(logFilePath).HasNoMatchForXpath("/WritingSystemChangeLog/Changes/Delete/Id[text()='en']");
            }
        }
        public void GenerateXHTMLForEntry_PrimaryEntryReferencesWork_ComplexFormOfEntry()
        {
            var mainRevEntryNode = PreparePrimaryEntryReferencesConfigSetup();
            var reversalEntry    = CreateInterestingEnglishReversalEntry("spokesmanRevForm", "porte-parole", "spokesman:gloss");
            var referringSense   = reversalEntry.ReferringSenses.First();
            var paroleEntry      = CXGTests.CreateInterestingLexEntry(Cache, "parole", "speech");

            paroleEntry.SummaryDefinition.SetAnalysisDefaultWritingSystem("summDefn");
            CXGTests.CreateComplexForm(Cache, paroleEntry, referringSense.Owner as ILexEntry, true);
            //SUT
            var          result        = ConfiguredXHTMLGenerator.GenerateXHTMLForEntry(reversalEntry, mainRevEntryNode, null, DefaultSettings);
            const string headwordXpath = referringSenseXpath + "/span[@class='headword']/span[@lang='fr']//a[text()='porte-parole']";

            AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(headwordXpath, 1);
            const string refTypeXpath = entryRefTypeXpath + "/span[@class='abbreviation']/span[@lang='en' and text()='comp. of']";

            AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(refTypeXpath, 1);
            AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(refHeadwordXpath, 1);
            const string glossOrSummDefXpath = primaryEntryXpath + "/span[@class='glossorsummary']/span[@lang='en' and text()='summDefn']";

            AssertThatXmlIn.String(result).HasSpecifiedNumberOfMatchesForXpath(glossOrSummDefXpath, 1);
        }
Beispiel #27
0
        public void MigrateBasicPageWith2PartLineage_CopiesTextAndImage()
        {
            SetDom(@"<div class='bloom-page' data-pagelineage='5dcd48df-e9ab-4a07-afd4-6a24d0398382;426e78a9-34d3-47f1-8355-ae737470bb6e' id='thePage'>
			   <div class='marginBox'>
					<div class='bloom-imageContainer bloom-leadingElement'><img data-license='cc-by-nc-sa' data-copyright='Copyright © 2012, LASI' style='width: 608px; height: 471px; margin-left: 199px; margin-top: 0px;' src='erjwx3bl.q3c.png' alt='This picture, erjwx3bl.q3c.png, is missing or was loading too slowly.' height='471' width='608'></img></div>
					<div aria-describedby='qtip-1' data-hasqtip='true' class='bloom-translationGroup bloom-trailingElement normal-style'>
						<div aria-describedby='qtip-0' data-hasqtip='true' class='bloom-editable normal-style bloom-content1' contenteditable='true' lang='en'>
							There was an old man called Bilanga who was very tall and also not yet married.
						</div>

						<div data-hasqtip='true' class='bloom-editable normal-style' contenteditable='true' lang='pis'>
							Wanfala olman nem blong hem Bilanga barava tol an hem no marit tu.
						</div>
						<div data-hasqtip='true' class='bloom-editable normal-style' contenteditable='true' lang='xyz'>
							Translation into xyz, the primary language.
						</div>
						<div class='bloom-editable' contenteditable='true' lang='z'></div>
					</div>
				</div>
			</div>
			"            );
            var book = CreateBook();
            var dom  = book.RawDom;
            var page = (XmlElement)dom.SafeSelectNodes("//div[@id='thePage']")[0];

            book.BringPageUpToDate(page);

            var newPage = (XmlElement)dom.SafeSelectNodes("//div[@id='thePage']")[0];

            CheckPageIsCustomizable(newPage);
            CheckPageLineage(page, newPage, "5dcd48df-e9ab-4a07-afd4-6a24d0398382", "adcd48df-e9ab-4a07-afd4-6a24d0398382");
            CheckEditableText(newPage, "en", "There was an old man called Bilanga who was very tall and also not yet married.");
            CheckEditableText(newPage, "pis", "Wanfala olman nem blong hem Bilanga barava tol an hem no marit tu.");
            CheckEditableText(newPage, "xyz", "Translation into xyz, the primary language.");
            CheckEditableText(newPage, "z", "");
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//img[@data-license='cc-by-nc-sa' and @data-copyright='Copyright © 2012, LASI' and @src='erjwx3bl.q3c.png']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//img", 1);
            Assert.That(newPage.SafeSelectNodes("//div[@lang='z' and contains(@class,'bloom-editable')]"), Has.Count.EqualTo(1), "Failed to remove old child element");
        }
        public void Run_ThreeEntriesWithTwoDifferentProperties_MergeToTwo()
        {
            const string contents =
                @"<entry id='foo' GUID1 dateModified='2006-10-02T01:42:57Z'>
				<lexical-unit>
				  <form lang='etr'>
					<text>bandazi</text>
				  </form>
				</lexical-unit>
				<field type='Dialect'>
					<form lang='en'><text>Northern</text></form>
				</field>
			</entry>
			<entry id='foo' GUID2 dateModified='2006-10-03T01:42:57Z'>
				<lexical-unit>
				  <form lang='etr'>
					<text>bandazi</text>
				  </form>
				</lexical-unit>
				<field type='Dialect'>
					<form lang='en'><text>Southern</text></form>
				</field>
			</entry>
			<entry id='foo' GUID3 dateModified='2006-10-04T01:42:57Z'>
				<lexical-unit>
				  <form lang='etr'>
					<text>bandazi</text>
				  </form>
				</lexical-unit>
				<field type='Dialect'>
					<form lang='en'><text>Northern</text></form>
				</field>
			</entry>"            ;

            Run(contents);
            AssertThatXmlIn.Dom(_resultDom).HasSpecifiedNumberOfMatchesForXpath("//entry", 2);
            AssertThatXmlIn.Dom(_resultDom).HasSpecifiedNumberOfMatchesForXpath("//entry/field/form/text[text()='Southern']", 1);
            AssertThatXmlIn.Dom(_resultDom).HasSpecifiedNumberOfMatchesForXpath("//entry/field/form/text[text()='Northern']", 1);
        }
        public void CheckCreditsPageAccessibility()
        {
            var pageData = GetPageNData(4);

            // Verify the ARIA roles and labels for the Bloom credits page.
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:*[@role='contentinfo']", _ns, 5);
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:*[@aria-label]", _ns, 6);
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:div[@role='contentinfo' and @aria-label='Credits Page']", _ns, 1);

            // Check our standard subsections of the credits page as well.
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:div[@role='contentinfo' and @aria-label='Copyright']", _ns, 1);
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:div[@role='contentinfo' and @aria-label='Version Acknowledgments']", _ns, 1);
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:div[@role='contentinfo' and @aria-label='Original Copyright']", _ns, 1);
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:div[@role='contentinfo' and @aria-label='Original Acknowledgments']", _ns, 1);

            // Check the page break references.
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:span[@role='doc-pagebreak']", _ns, 1);
            AssertThatXmlIn.String(pageData).HasSpecifiedNumberOfMatchesForXpath("//xhtml:span[@role='doc-pagebreak' and @aria-label='Credits Page']", _ns, 1);

            XmatterPageHasContentInfoNotMain(pageData);
            EpubBackmatterPageHasNoDescribableImage(pageData);
        }
        public void CreateBookOnDiskFromTemplate_OriginalCC0_LicenseRemoved()
        {
            var originalSource = BloomFileLocator.GetFactoryBookTemplateDirectory("Basic Book");

            using (var tempFolder = new TemporaryFolder("BasicBookCc0"))
                using (var destFolder = new TemporaryFolder("OriginalCC0_BookIsBy"))
                {
                    var source = Path.Combine(tempFolder.Path, "Basic Book");
                    if (Directory.Exists(source))
                    {
                        Directory.Delete(source, true);
                    }
                    DirectoryUtilities.CopyDirectory(originalSource, tempFolder.Path);
                    var htmPath = Path.Combine(source, "Basic Book.html");
                    var content = RobustFile.ReadAllText(htmPath);
                    // insert cc0 stuff in data div
                    var replacement = @"<div id='bloomDataDiv'><div data-book='licenseUrl' lang='*'>
            http://creativecommons.org/publicdomain/zero/1.0/
        </div>
		<div data-book='licenseUrl' lang='en'>
            http://creativecommons.org/publicdomain/zero/1.0/
        </div>
		<div data-book='licenseUrl'>
            http://creativecommons.org/publicdomain/zero/1.0/
        </div>
        <div data-book='licenseDescription' lang='en'>
            You can copy, modify, and distribute this work, even for commercial purposes, all without asking permission.
        </div>
		<div data-book='licenseNotes'>This should be removed too</div>"        .Replace("'", "\"");
                    var patched     = content.Replace("<div id=\"bloomDataDiv\">", replacement);
                    RobustFile.WriteAllText(htmPath, patched);
                    var bookPath       = GetPathToHtml(_starter.CreateBookOnDiskFromTemplate(source, destFolder.Path));
                    var assertThatBook = AssertThatXmlIn.HtmlFile(bookPath);
                    assertThatBook.HasNoMatchForXpath("//div[@data-book='licenseUrl']");
                    assertThatBook.HasNoMatchForXpath("//div[@data-book='licenseDescription']");
                    assertThatBook.HasNoMatchForXpath("//div[@data-book='licenseNotes']");
                }
        }