예제 #1
0
        public void SaveAsHTM_HasEmptyParagraphsAndCites_RetainsThem()
        {
            var pattern = "<p></p><p></p><p>a</p><p></p><p>b</p><p/><cite></cite><cite /><cite data-book='originalTitle'></cite><cite data-book='originalTitle'/>";
            var dom     = new XmlDocument();

            dom.LoadXml("<!DOCTYPE html><html><body>" +
                        pattern +
                        "</body></html>");
            using (var temp = new TempFile())
            {
                XmlHtmlConverter.SaveDOMAsHtml5(dom, temp.Path);
                var r       = new Regex("<p");
                var text    = File.ReadAllText(temp.Path);
                var matches = r.Matches(text);
                Assert.AreEqual(6, matches.Count, text);
                Assert.AreEqual(4, new Regex("<cite").Matches(text).Count, text);
                //this one also exercises XmlHtmlConverter.GetXmlDomFromHtmlFile, so we're not really testing anymore
                var assertHtmlFile = AssertThatXmlIn.HtmlFile(temp.Path);
                assertHtmlFile.HasSpecifiedNumberOfMatchesForXpath("//p", 6);
                assertHtmlFile.HasSpecifiedNumberOfMatchesForXpath("//cite", 4);
            }
        }
예제 #2
0
        public void ChangePicture_PictureIsFromOutsideProject_PictureCopiedAndAttributeChanged_AndMetadataSaved()
        {
            var dom = new XmlDocument();

            dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>");

            using (var src = new TemporaryFolder("bloom pictures test source"))
                using (var dest = new TemporaryFolder("bloom picture tests dest"))
                {
                    var newImagePath = src.Combine("new.png");
                    using (var original = MakeSamplePngImage(newImagePath))
                    {
                        original.Metadata.Creator    = "Some nice user";
                        original.Metadata.HasChanges = true;
                        ChangePicture(dest.Path, dom, "two", original);
                        var pathToNewImage = dest.Combine("new.png");
                        Assert.IsTrue(File.Exists(pathToNewImage));
                        AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.png']", 1);
                        var metadataFromImage = Metadata.FromFile(pathToNewImage);
                        Assert.That(metadataFromImage.Creator, Is.EqualTo("Some nice user"));
                    }
                }
        }