@@ -11,8 +11,8 @@ class AnnotationObjectNumbersTest extends \Yoast\PHPUnitPolyfills\TestCases\Test
1111 use PageStreams;
1212
1313 /**
14- * Every /Annots entry is an annotation of its page, and every /Popup, /Parent, /EF, /AP and radio /Parent
15- * reference names an object of the kind it should
14+ * Every /Annots entry is an annotation of its page, and every /Popup, /Parent, /EF, /AP and radio or button /Parent
15+ * reference names an object of the kind it should. A field that gathers widgets is listed by /Fields, not /Annots.
1616 *
1717 * @dataProvider documents
1818 *
@@ -30,11 +30,14 @@ public function testReferencesNameTheRightObjects($config, $forms, $expected)
3030 $ this ->assertEveryObjectWritten ($ pdf );
3131
3232 $ subtypes = [];
33+ $ listed = [];
34+ $ parents = [];
3335 foreach ($ this ->pageObjects ($ pdf ) as $ i => $ page ) {
3436 $ refs = $ this ->annotsOf ($ pdf , $ page );
3537 $ subtypes [$ i ] = [];
3638
3739 foreach ($ refs as $ ref ) {
40+ $ listed [] = $ ref ;
3841 $ annot = $ this ->object ($ pdf , $ ref );
3942 $ this ->assertStringContainsString ('/Type /Annot ' , $ annot );
4043 preg_match ('/\/Subtype \/(\w+)/ ' , $ annot , $ subtype );
@@ -72,11 +75,24 @@ public function testReferencesNameTheRightObjects($config, $forms, $expected)
7275
7376 if ($ subtype [1 ] === 'Widget ' && preg_match ('/\/Parent (\d+) 0 R/ ' , $ annot , $ group )) {
7477 $ this ->assertMatchesRegularExpression ('/\/Kids \[[^\]]*\b ' . $ ref . ' 0 R/ ' , $ this ->object ($ pdf , $ group [1 ]));
78+ $ this ->assertStringNotContainsString ('/T ( ' , $ annot , 'A kid takes its name from its field ' );
79+ $ parents [] = $ group [1 ];
7580 }
7681 }
7782 }
7883
7984 $ this ->assertSame ($ expected , $ subtypes );
85+
86+ if ($ forms ) {
87+ preg_match ('/\/Fields \[([^\]]*)\]/ ' , $ pdf , $ list );
88+ preg_match_all ('/(\d+) 0 R/ ' , $ list [1 ], $ fields );
89+ $ parents = array_unique ($ parents );
90+ $ this ->assertCount (4 , $ parents , 'Two radio groups and two groups of buttons ' );
91+ foreach ($ parents as $ parent ) {
92+ $ this ->assertNotContains ($ parent , $ listed , 'A field is not an annotation ' );
93+ $ this ->assertContains ($ parent , $ fields [1 ]);
94+ }
95+ }
8096 }
8197
8298 /**
@@ -87,24 +103,25 @@ public function testReferencesNameTheRightObjects($config, $forms, $expected)
87103 public function documents ()
88104 {
89105 $ notes = ['Link ' , 'Text ' , 'Popup ' , 'Text ' , 'Text ' , 'Text ' , 'Popup ' ];
90- $ widgets = ['Widget ' , 'Widget ' , 'Widget ' , 'Widget ' , 'Widget ' ];
106+ $ widgets = ['Widget ' , 'Widget ' , 'Widget ' , 'Widget ' , 'Widget ' , ' Widget ' , ' Widget ' , ' Widget ' , ' Widget ' ];
91107 $ second = ['Link ' , 'Text ' , 'Popup ' ];
92108
93109 $ withFile = ['Link ' , 'Text ' , 'Popup ' , 'FileAttachment ' , 'Text ' , 'Text ' , 'Popup ' ];
94110
95111 return [
96- 'file not allowed, forms ' => [['mode ' => 'c ' , 'useActiveForms ' => true ], true , [array_merge ($ notes , $ widgets ), array_merge ($ second , ['Widget ' , 'Widget ' , 'Widget ' ])]],
97- 'embedded fonts, forms ' => [['useActiveForms ' => true ], true , [array_merge ($ notes , $ widgets ), array_merge ($ second , ['Widget ' , 'Widget ' , 'Widget ' ])]],
98- 'file allowed, forms ' => [['mode ' => 'c ' , 'useActiveForms ' => true , 'allowAnnotationFiles ' => true , 'allowHtmlAnnotationFiles ' => true ], true , [array_merge ($ withFile , $ widgets ), array_merge ($ second , ['Widget ' , 'Widget ' , 'Widget ' ])]],
112+ 'file not allowed, forms ' => [['mode ' => 'c ' , 'useActiveForms ' => true ], true , [array_merge ($ notes , $ widgets ), array_merge ($ second , ['Widget ' , 'Widget ' , 'Widget ' , ' Widget ' , ' Widget ' ])]],
113+ 'embedded fonts, forms ' => [['useActiveForms ' => true ], true , [array_merge ($ notes , $ widgets ), array_merge ($ second , ['Widget ' , 'Widget ' , 'Widget ' , ' Widget ' , ' Widget ' ])]],
114+ 'file allowed, forms ' => [['mode ' => 'c ' , 'useActiveForms ' => true , 'allowAnnotationFiles ' => true , 'allowHtmlAnnotationFiles ' => true ], true , [array_merge ($ withFile , $ widgets ), array_merge ($ second , ['Widget ' , 'Widget ' , 'Widget ' , ' Widget ' , ' Widget ' ])]],
99115 'PDF/A-2 appearances, file not a PDF/A ' => [['PDFA ' => true , 'PDFAauto ' => true , 'PDFAversion ' => '2-B ' , 'allowAnnotationFiles ' => true , 'allowHtmlAnnotationFiles ' => true ], false , [$ notes , $ second ]],
100- 'PDF/A-2 appearances, forms ' => [['PDFA ' => true , 'PDFAauto ' => true , 'PDFAversion ' => '2-B ' , 'useActiveForms ' => true ], true , [array_merge ($ notes , $ widgets ), array_merge ($ second , ['Widget ' , 'Widget ' , 'Widget ' ])]],
116+ 'PDF/A-2 appearances, forms ' => [['PDFA ' => true , 'PDFAauto ' => true , 'PDFAversion ' => '2-B ' , 'useActiveForms ' => true ], true , [array_merge ($ notes , $ widgets ), array_merge ($ second , ['Widget ' , 'Widget ' , 'Widget ' , ' Widget ' , ' Widget ' ])]],
101117 'PDF/A-3 appearances and file ' => [['PDFA ' => true , 'PDFAauto ' => true , 'PDFAversion ' => '3-B ' , 'allowAnnotationFiles ' => true , 'allowHtmlAnnotationFiles ' => true ], false , [$ withFile , $ second ]],
102118 ];
103119 }
104120
105121 /**
106122 * Two pages of links, notes with and without popups, a note with a file and, when asked, form widgets with a
107- * radio group on each page
123+ * radio group on each page, two buttons named go on the first and one on the second, and buttons named b and
124+ * lone
108125 *
109126 * @param bool $forms
110127 *
@@ -118,13 +135,16 @@ private function html($forms)
118135 if ($ forms ) {
119136 $ html .= '<form><input type="text" name="t1" value="x" onchange="alert(1)" /> <input type="checkbox" name="c1" value="1" checked="checked" /> '
120137 . ' <input type="radio" name="r1" value="a" checked="checked" /> <input type="radio" name="r1" value="b" /> '
121- . ' <select name="s1" onchange="x()"><option value="1">1</option></select></form> ' ;
138+ . ' <select name="s1" onchange="x()"><option value="1">1</option></select> '
139+ . ' <input type="button" name="go" value="A" onclick="a()" /> <input type="submit" name="go" value="B" /> '
140+ . ' <input type="image" name="b" src=" ' . __DIR__ . '/../data/img/ratio-16x9.png" onclick="b()" /> <input type="reset" name="lone" /></form> ' ;
122141 }
123142
124143 $ html .= '<pagebreak /><p id="b"><a href="https://example.com">ext</a> <annotation content="Second" popup="true" /></p> ' ;
125144
126145 if ($ forms ) {
127- $ html .= '<form><input type="radio" name="r2" value="c" /> <input type="radio" name="r2" value="d" checked="checked" /> <input type="text" name="t2" /></form> ' ;
146+ $ html .= '<form><input type="radio" name="r2" value="c" /> <input type="radio" name="r2" value="d" checked="checked" /> <input type="text" name="t2" /> '
147+ . ' <input type="button" name="go" value="C" onclick="c()" /> <input type="image" name="b" src=" ' . __DIR__ . '/../data/img/ratio-9x16.png" /></form> ' ;
128148 }
129149
130150 return $ html ;
0 commit comments