mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-20 20:07:57 +08:00
handle checked state of radio buttons and checkboxes
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using AcroForms.Fields;
|
||||
using Xunit;
|
||||
|
||||
public class AcroFormsBasicFieldsTests
|
||||
@@ -53,5 +54,38 @@
|
||||
Assert.Equal(18, fields.Count);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsRadioButtonState()
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilename(), ParsingOptions.LenientParsingOff))
|
||||
{
|
||||
var form = document.GetForm();
|
||||
var radioButtons = form.Fields.OfType<AcroRadioButtonsField>().ToList();
|
||||
|
||||
Assert.Equal(2, radioButtons.Count);
|
||||
|
||||
// ReSharper disable once PossibleInvalidOperationException
|
||||
var ordered = radioButtons.OrderBy(x => x.Children.Min(y => y.Bounds.Value.Left)).ToList();
|
||||
|
||||
var left = ordered[0];
|
||||
|
||||
Assert.Equal(2, left.Children.Count);
|
||||
foreach (var acroFieldBase in left.Children)
|
||||
{
|
||||
var button = Assert.IsType<AcroRadioButtonField>(acroFieldBase);
|
||||
Assert.False(button.IsSelected);
|
||||
}
|
||||
|
||||
var right = ordered[1];
|
||||
Assert.Equal(2, right.Children.Count);
|
||||
|
||||
var buttonOn = Assert.IsType<AcroRadioButtonField>(right.Children[0]);
|
||||
Assert.True(buttonOn.IsSelected);
|
||||
|
||||
var buttonOff = Assert.IsType<AcroRadioButtonField>(right.Children[1]);
|
||||
Assert.False(buttonOff.IsSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user