Merge branch 'master' of linz:/srv/git/php-utility-classes
[php-utility-classes.git] / tests / ua_test.php
index 97309b3b84102bbcfa2b93d37603a335544bf793..d7dfda247ed5bc496563525e4f51d4e77ba4c716 100644 (file)
 <?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/. */
 
-$wrapper->pgtop("KaiRo's Browser-Test");
+include('../classes/useragent.php-class');
+include('../classes/document.php-class');
 
 // set default time zone - right now, always the one the server is in!
 date_default_timezone_set('Europe/Vienna');
 
-$httpvars = $util->getHTTPvars();
-if (strlen($httpvars["ua"])) {
-  $ua = new userAgent($httpvars["ua"]);
+// Start HTML document as a DOM object.
+extract(ExtendedDocument::initHTML5()); // sets $document, $html, $head, $title, $body
+$document->formatOutput = true; // we want a nice output
+
+$style = $head->appendElement('link');
+$style->setAttribute('rel', 'stylesheet');
+$style->setAttribute('href', 'test.css');
+$title->appendText('User Agent Test');
+$h1 = $body->appendElement('h1', 'User Agent Test');
+
+if (strlen($_REQUEST["ua"])) {
+  $ua = new userAgent($_REQUEST["ua"]);
 }
 else {
   $ua = new userAgent;
 }
 
-print("<h1>KaiRo's Browser-Test</h1>\n");
+$para = $body->appendElement('p', 'I read the following user agent string from '.(strlen($httpvars['ua'])?'your input':'your browser').':');
+$para->appendElement('br');
+$para->appendElement('b', $ua->getUAString());
 
-print("I read the following user agent string from ".(strlen($httpvars["ua"])?"your input":"your browser").":\n<br>");
-print("<b>".$ua->getUAString()."</b>\n");
-
-print("<br><br>The browser brand is reported as &quot;<b>".$ua->getBrand()."</b>&quot;\n");
-print("<br>The browser version is reported as &quot;<b>".$ua->getVersion()."</b>&quot;\n");
-print("<br>The browser engine is reported as &quot;<b>".$ua->getEngine()."</b>&quot;\n");
-print("<br>The engine version is reported as &quot;<b>".$ua->getEngineVersion()."</b>&quot;\n");
-print("<br>The operating system is reported as &quot;<b>".$ua->getOS()."</b>&quot;\n");
-print("<br>The system platform is reported as &quot;<b>".$ua->getPlatform()."</b>&quot;\n");
-print("<br>The browser language is reported as &quot;<b>".$ua->getLanguage()."</b>&quot;\n");
+$ulist = $body->appendElement('ul');
+$ulist->setAttribute('class', 'flat');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The browser brand is reported as "');
+$litem->appendElement('b', $ua->getBrand());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The browser version is reported as "');
+$litem->appendElement('b', $ua->getVersion());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The browser engine is reported as "');
+$litem->appendElement('b', $ua->getEngine());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The engine version is reported as "');
+$litem->appendElement('b', $ua->getEngineVersion());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The operating system is reported as "');
+$litem->appendElement('b', $ua->getOS());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The system platform is reported as "');
+$litem->appendElement('b', $ua->getPlatform());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The browser language is reported as "');
+$litem->appendElement('b', $ua->getLanguage());
+$litem->appendText('"');
 if ($ua->hasEngine('gecko')) {
-  print("<br>The Gecko date is reported as &quot;<b>".$ua->getGeckoDate()."</b>&quot;\n");
-  print("<br>The full Gecko date/time is reported as &quot;<b>".date('r',$ua->getGeckoTime())."</b>&quot;\n");
+  $litem = $ulist->appendElement('li');
+  $litem->appendText('The Gecko date is reported as "');
+  $litem->appendElement('b', $ua->getGeckoDate());
+  $litem->appendText('"');
+  $litem = $ulist->appendElement('li');
+  $litem->appendText('The full Gecko date/time is reported as "');
+  $litem->appendElement('b', date('r',$ua->getGeckoTime()));
+  $litem->appendText('"');
+}
+$litem = $ulist->appendElement('li');
+$litem->setAttribute('class', 'summary');
+$litem->appendText('I conclude this must be ');
+$litem->appendElement('b', $ua->getBrand()." ".$ua->getVersion());
+$litem->appendText('.');
+$litem = $ulist->appendElement('li');
+$litem->appendText('This is ');
+$litem->appendElement('b', ($ua->isBot()?'an':'no'));
+$litem->appendText(' automated robot.');
+
+$para = $body->appendElement('p', 'Accepted Languages:');
+foreach ($acclang as $lang=>$q) {
+  $para->appendText($lang.'('.$q.') ');
 }
-print("<br><br>I conclude this must be <b>".$ua->getBrand()." ".$ua->getVersion()."</b>\n");
-print("<br>This is <b>".($ua->isBot()?"an":"no")."</b> automated robot.\n");
-
-$acclang = $ua->getAcceptLanguages();
-print("<br><br>Accepted Languages: ");
-foreach ($acclang as $lang=>$q) { print($lang."(".$q.") "); }
-print("\n");
-
-print("<br><br>Test the following UA string (leave empty to read it from your browser):\n");
-print("<form method=\"POST\" action=\"\"><p>\n");
-print("<input type=\"text\" name=\"ua\" value=\"".htmlentities($ua->getUAString())."\" size=\"80\" maxlength=\"150\">\n");
-print("<br><input type=\"submit\" value=\"Test\"></p></form>\n");
-$wrapper->pgbottom();
+
+$para = $body->appendElement('p', 'Test the following UA string (leave empty to read it from your browser):');
+$form = $body->appendForm('', 'POST', 'uaform');
+$form->appendInputText('ua', 150, 80, null, $ua->getUAString());
+$form->appendElement('br');
+$form->appendInputSubmit(_('Test'));
+
+$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());
 ?>