Debian Codegraph @

extensions/Math/tests/phpunit/unit/WikiTexVC/MMLTestUtilHTML.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Math\WikiTexVC\MMLmappings\Util;
4
5 /**
6 * This class contains functions to generate a
7 * HTML File which shows the formula converted to MathML
8 * by WikiTexVC
9 * @author Johannes Stegmüller
10 */
11 class MMLTestUtilHTML {
12
13 public static function generateHTMLtableItem( string $input, bool $bold = false ): string {
14 if ( !$bold ) {
15 return "<td class=\"tg-0lax\">" . $input . "</td>";
16 } else {
17 return "<td class=\"tg-0lax\">" . "<b>" . $input . "</b>" . "</td>";
18 }
19 }
20
21 public static function generateHTMLEnd( string $filePath, bool $active = true ) {
22 if ( !$active ) {
23 return;
24 }
25 $file = fopen( $filePath, 'a' );
26 fwrite( $file, "</tbody></table>" );
27 fclose( $file );
28 }
29
30 public static function generateHTMLtableRow(
31 string $filePath,
32 array $rows,
33 bool $bold = false,
34 bool $active = true
35 ) {
36 if ( !$active ) {
37 return;
38 }
39 $file = fopen( $filePath, 'a' );
40
41 $stringData = "<tr>";
42 foreach ( $rows as $row ) {
43 $stringData .= self::generateHTMLtableItem( $row, $bold );
44 }
45 $stringData .= "</tr>";
46
47 fwrite( $file, $stringData );
48
49 fclose( $file ); // tbd only open close once for all tests
50 }
51
52 public static function generateHTMLstart(
53 string $filePath,
54 array $headrows = [ "name", "Tex-Input", "MathML(MathJax3)", "MathML(WikiTexVC)" ],
55 bool $active = true
56 ) {
57 if ( !$active ) {
58 return;
59 }
60
61 $htmlRows = "";
62 foreach ( $headrows as $header ) {
63 $htmlRows .= "<th class=\"tg-0lax\"><b>" . $header . "</b></th>";
64 }
65
66 $file = fopen( $filePath, 'w' ); // or die("error");
67 $stringData = /** @lang HTML */
68 <<<HTML
69 <!DOCTYPE html>
70 <html lang="en">
71 <head>
72 <meta charset="utf-8">
73 </head>
74 <style>
75 .tg {
76 border-collapse: collapse;
77 border-spacing: 0;
78 }
79 .tg td {
80 border-color: black;
81 border-style: solid;
82 border-width: 1px;
83 font-family: Arial, sans-serif;
84 font-size: 14px;
85 overflow: hidden;
86 padding: 10px 5px;
87 word-break: normal;
88 }
89 .tg th {
90 border-color: black;
91 border-style: solid;
92 border-width: 1px;
93 font-family: Arial,
94 sans-serif;
95 font-size: 14px;
96 font-weight: normal;
97 overflow: hidden;
98 padding: 10px 5px;
99 word-break: normal;
100 }
101 .tg .tg-0lax {
102 text-align: left;
103 vertical-align: top
104 }
105 </style>
106 <table class="tg">
107 <thead>
108 <tr>{$htmlRows}</tr>
109 </thead>
110 <tbody>
111 HTML;
112 fwrite( $file, $stringData );
113 fclose( $file );
114 }
115 }