KaiRo bug 401 - Convert UA tests to using ExtendedDocument, also updating the used...
[php-utility-classes.git] / tests / ua_list.php
index 3b417afd30053ccb5a604cd721e05b179fddb10e..5c2e5ceede0db15c1007e7f03961142242694645 100644 (file)
@@ -1,65 +1,79 @@
 <?php
 <?php
-$inc_class_util = true;
-$inc_class_ua = true;
-include('inchandler.inc');
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+include('../classes/useragent.php-class');
+include('../classes/document.php-class');
 
 // read string from this file
 $uafile = 'ua_list_raw.txt';
 
 
 // read string from this file
 $uafile = 'ua_list_raw.txt';
 
-$mycss = "th { font-size: 0.75em; }\n";
-$mycss .= "td.comment { font-size: 0.75em; text-align: center; font-weight: bold; }\n";
-$mycss .= "td.ua { font-size: 0.75em; }\n";
-
-$wrapper->pgtop('User Agents', $mycss);
+// Start HTML document as a DOM object.
+extract(ExtendedDocument::initHTML5()); // sets $document, $html, $head, $title, $body
+$document->formatOutput = true; // we want a nice output
 
 
-print('<h1>User Agents</h1>'."\n");
+$style = $head->appendElement('link');
+$style->setAttribute('rel', 'stylesheet');
+$style->setAttribute('href', 'test.css');
+$title->appendText('User Agents');
+$h1 = $body->appendElement('h1', 'User Agents');
 
 $ualist = is_readable($uafile)?file($uafile):array();
 
 if (count($ualist)) {
 
 $ualist = is_readable($uafile)?file($uafile):array();
 
 if (count($ualist)) {
-  print('<table class="border">'."\n");
-  print(' <tr>'."\n");
-  print('  <th>User Agent string</th>'."\n");
-  print('  <th>Brand</th>'."\n");
-  print('  <th>Version</th>'."\n");
-  print('  <th>Bot</th>'."\n");
-  print('  <th>Mob</th>'."\n");
-  print('  <th>Engine</th>'."\n");
-  print('  <th>eVer</th>'."\n");
-  print('  <th>OS</th>'."\n");
-  print('  <th>Platform</th>'."\n");
-  print('  <th>Lang</th>'."\n");
-  print(' </tr>'."\n");
+  $tbl = $body->appendElement('table');
+  $tbl->setAttribute('class', 'border');
+  $tbl->setAttribute('id', 'ualist');
+  $thead = $tbl->appendElement('thead');
+  $trow = $thead->appendElement('tr');
+  $trow->appendElement('th', 'User Agent string');
+  $trow->appendElement('th', 'Brand');
+  $trow->appendElement('th', 'Version');
+  $trow->appendElement('th', 'Bot');
+  $trow->appendElement('th', 'Mob');
+  $trow->appendElement('th', 'Engine');
+  $trow->appendElement('th', 'eVer');
+  $trow->appendElement('th', 'OS');
+  $trow->appendElement('th', 'Platform');
+  $trow->appendElement('th', 'Lang');
 
 
+  $tbody = $tbl->appendElement('tbody');
   foreach ($ualist as $uastring) {
     $uastring = trim($uastring);
     if (substr($uastring, 0, 1) == '#') {
       // comment
   foreach ($ualist as $uastring) {
     $uastring = trim($uastring);
     if (substr($uastring, 0, 1) == '#') {
       // comment
-      print(' <tr>'."\n");
-      print('  <td colspan="10" class="comment">'.substr($uastring, 1).'</td>'."\n");
-      print(' </tr>'."\n");
+      $trow = $tbody->appendElement('tr');
+      $cell = $trow->appendElement('td', substr($uastring, 1));
+      $cell->setAttribute('colspan', 10);
+      $cell->setAttribute('class', 'comment');
     }
     else {
       $ua = new userAgent($uastring);
     }
     else {
       $ua = new userAgent($uastring);
-      print(' <tr>'."\n");
-      print('  <td class="ua">'.$ua->getUAString().'</td>'."\n");
-      print('  <td>'.$ua->getBrand().'</td>'."\n");
-      print('  <td>'.$ua->getVersion().'</td>'."\n");
-      print('  <td>'.($ua->isBot()?'x':'-').'</td>'."\n");
-      print('  <td>'.($ua->isMobile()?'x':'-').'</td>'."\n");
-      print('  <td>'.$ua->getEngine().'</td>'."\n");
-      print('  <td>'.$ua->getEngineVersion().'</td>'."\n");
-      print('  <td>'.$ua->getOS().'</td>'."\n");
-      print('  <td>'.$ua->getPlatform().'</td>'."\n");
-      print('  <td>'.$ua->getLanguage().'</td>'."\n");
-      print(' </tr>'."\n");
+      $trow = $tbody->appendElement('tr');
+      $cell = $trow->appendElement('td', $ua->getUAString());
+      $cell->setAttribute('class', 'ua');
+      $trow->appendElement('td', $ua->getBrand());
+      $trow->appendElement('td', $ua->getVersion());
+      $trow->appendElement('td', ($ua->isBot()?'x':'-'));
+      $trow->appendElement('td', ($ua->isMobile()?'x':'-'));
+      $trow->appendElement('td', $ua->getEngine());
+      $trow->appendElement('td', $ua->getEngineVersion());
+      $trow->appendElement('td', $ua->getOS());
+      $trow->appendElement('td', $ua->getPlatform());
+      $trow->appendElement('td', $ua->getLanguage());
     }
   }
     }
   }
-  print('</table>'."\n");
 }
 else {
 }
 else {
-  print('No User Agent strings found in file "'.$uafile.'".'."\n");
+  $body->appendElement('p', 'No User Agent strings found in file "'.$uafile.'".');
 }
 
 }
 
-$wrapper->pgbottom();
+$footer = $body->appendElement('footer', 'Page code under Mozilla Public License, code available at ');
+$footer->setAttribute('id', 'copyright');
+$footer->appendLink('https://github.com/KaiRo-at/php-utility-classes', 'GitHub');
+$footer->appendText('.');
+
+// Send HTML to client.
+print($document->saveHTML());
 ?>
 ?>