Browse Source

Add hyperlink tests to XWPFParagraph

Implemented a new test method `TestAddingHyperlinks` in `TestXWPFParagraph.cs`. This method verifies the functionality of adding hyperlinks to paragraphs in Word documents, including the creation of hyperlink runs, the count of runs, and the correct indexing of hyperlinks within the paragraph's runs and their XML representation.
pull/1535/head
Bruno Gonçalves 3 months ago
parent
commit
5c26dbdd3b
  1. 24
      testcases/ooxml/XWPF/UserModel/TestXWPFParagraph.cs

24
testcases/ooxml/XWPF/UserModel/TestXWPFParagraph.cs

@ -587,6 +587,30 @@ namespace TestCases.XWPF.UserModel
ClassicAssert.IsNull(p.GetRun(null));
}
[Test]
public void TestAddingHyperlinks()
{
XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("sample.docx");
XWPFParagraph p = doc.Paragraphs[0];
ClassicAssert.AreEqual(2, p.Runs.Count);
string rId = p.Part.GetPackagePart().AddExternalRelationship("https://www.google.com", XWPFRelation.HYPERLINK.Relation).Id;
XWPFHyperlinkRun hr1 = p.CreateHyperlinkRun(rId);
hr1.SetText("link1");
ClassicAssert.AreEqual(3, p.Runs.Count);
ClassicAssert.AreEqual(2, p.Runs.IndexOf(hr1));
ClassicAssert.AreEqual(2, p.GetCTP().Items.IndexOf(hr1.GetCTHyperlink()));
XWPFHyperlinkRun hr2 = p.InsertNewHyperlinkRun(1, rId);
hr2.SetText("link2");
ClassicAssert.AreEqual(4, p.Runs.Count);
ClassicAssert.AreEqual(1, p.Runs.IndexOf(hr2));
ClassicAssert.AreEqual(1, p.GetCTP().Items.IndexOf(hr2.GetCTHyperlink()));
}
[Test]
public void Test58067()
{

Loading…
Cancel
Save