X-Git-Url: https://git-public.kairo.at/?p=php-utility-classes.git;a=blobdiff_plain;f=tests%2Fua_test.php;h=d7dfda247ed5bc496563525e4f51d4e77ba4c716;hp=bf72e447ced1a9496c2d4621a75ba3b5e88886f9;hb=34bf6915dfc529bfb3408069ab7c62bbc218f461;hpb=880bcb60d557851e01051e9382decd36ec7665a1 diff --git a/tests/ua_test.php b/tests/ua_test.php index bf72e44..d7dfda2 100644 --- a/tests/ua_test.php +++ b/tests/ua_test.php @@ -4,16 +4,20 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ 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'); -print("\n"); -print("\n\n"); -print(" \n"); -print(" \n"); -print(" ".'User Agent Test'."\n"); -print("\n\n"); +// 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"]); @@ -22,37 +26,76 @@ else { $ua = new userAgent; } -print("

User Agent Test

\n"); - -print("I read the following user agent string from ".(strlen($httpvars["ua"])?"your input":"your browser").":\n
"); -print("".$ua->getUAString()."\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("

The browser brand is reported as "".$ua->getBrand().""\n"); -print("
The browser version is reported as "".$ua->getVersion().""\n"); -print("
The browser engine is reported as "".$ua->getEngine().""\n"); -print("
The engine version is reported as "".$ua->getEngineVersion().""\n"); -print("
The operating system is reported as "".$ua->getOS().""\n"); -print("
The system platform is reported as "".$ua->getPlatform().""\n"); -print("
The browser language is reported as "".$ua->getLanguage().""\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("
The Gecko date is reported as "".$ua->getGeckoDate().""\n"); - print("
The full Gecko date/time is reported as "".date('r',$ua->getGeckoTime()).""\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("

I conclude this must be ".$ua->getBrand()." ".$ua->getVersion()."\n"); -print("
This is ".($ua->isBot()?"an":"no")." automated robot.\n"); - -$acclang = $ua->getAcceptLanguages(); -print("

Accepted Languages: "); -foreach ($acclang as $lang=>$q) { print($lang."(".$q.") "); } -print("\n"); - -print("

Test the following UA string (leave empty to read it from your browser):\n"); -print("

\n"); -print("getUAString())."\" size=\"80\" maxlength=\"150\">\n"); -print("

\n"); - -print("
\n"); -print("Page code under Mozilla Public License, code available at GitHub.\n"); -print("
\n"); -print("\n"); + +$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()); ?>