From b55e856346117c92de566310d11209d85c46067d Mon Sep 17 00:00:00 2001
From: Brett Bieber <brett.bieber@gmail.com>
Date: Thu, 13 Jan 2011 17:43:55 +0000
Subject: [PATCH] Add some tests for the redirect rules.

---
 README                         |  2 +-
 tests/config.sample.php        | 12 +++++++++++
 tests/redirected_uas.phpt      | 37 ++++++++++++++++++++++++++++++++++
 tests/rewrite_rules.phpt       | 15 ++++++++++++++
 tests/rewritetarget/index.php  |  3 +++
 tests/rewrittendir/file1.shtml |  1 +
 6 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 tests/config.sample.php
 create mode 100644 tests/redirected_uas.phpt
 create mode 100644 tests/rewrite_rules.phpt
 create mode 100644 tests/rewritetarget/index.php
 create mode 100644 tests/rewrittendir/file1.shtml

diff --git a/README b/README
index 229448d..7a03673 100644
--- a/README
+++ b/README
@@ -16,7 +16,7 @@ RewriteCond %{QUERY_STRING} !mobile=no$
 RewriteCond %{HTTP_COOKIE} !^.*wdn_mobile=no.*$ [NC]
 
 # If iPad user, don't auto-redirect to mobile
-RewriteCond %{HTTP_USER_AGENT} !ipad [NC]
+RewriteCond %{HTTP_USER_AGENT} !iPad [NC]
 
 # if the browser accepts these mime-types, it's definitely mobile, or pretending to be
 RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
diff --git a/tests/config.sample.php b/tests/config.sample.php
new file mode 100644
index 0000000..f72a3b3
--- /dev/null
+++ b/tests/config.sample.php
@@ -0,0 +1,12 @@
+<?php
+
+// To run the tests, they must be web-accessible. Set this to the path.
+$baseURL = 'http://ucommbieber.unl.edu/workspace/wdnmobile/tests/';
+
+
+/*
+ *  You also must place the rewrite rules inside .htaccess in rewrittendir.
+ *  
+ *  Be sure to set the redirect url to rewritetarget
+ *  
+ */
diff --git a/tests/redirected_uas.phpt b/tests/redirected_uas.phpt
new file mode 100644
index 0000000..d450441
--- /dev/null
+++ b/tests/redirected_uas.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Apache rewrite rules test
+--FILE--
+<?php
+require_once __DIR__ . '/config.inc.php';
+
+$path = parse_url($baseURL, PHP_URL_PATH);
+
+$redirected_uas = array();
+$redirected_uas[] = 'iPhone';
+
+foreach ($redirected_uas as $ua) {
+
+    // Create a stream
+    $opts = array(
+      'http'=>array(
+        'max_redirects' => 3,
+        'method'        => 'GET',
+        'user_agent'    => $ua,
+      )
+    );
+    
+    $context = stream_context_create($opts);
+    
+    // Open the file using the HTTP headers set above
+    $data = file_get_contents($baseURL . 'rewrittendir/file1.shtml', false, $context);
+    
+    if ($data !== $path . 'rewritetarget/index.php?view=proxy&u='.$baseURL.'rewrittendir/file1.shtml') {
+        echo $data;
+    }
+
+}
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
\ No newline at end of file
diff --git a/tests/rewrite_rules.phpt b/tests/rewrite_rules.phpt
new file mode 100644
index 0000000..da1f2d5
--- /dev/null
+++ b/tests/rewrite_rules.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Apache rewrite rules test
+--FILE--
+<?php
+require_once __DIR__ . '/config.inc.php';
+
+$data = file_get_contents($baseURL . 'rewrittendir/file1.shtml');
+if ($data !== 'rewrittendir/file1.shtml') {
+    echo $data;
+}
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
\ No newline at end of file
diff --git a/tests/rewritetarget/index.php b/tests/rewritetarget/index.php
new file mode 100644
index 0000000..1096be6
--- /dev/null
+++ b/tests/rewritetarget/index.php
@@ -0,0 +1,3 @@
+<?php
+echo $_SERVER['REQUEST_URI'];
+?>
\ No newline at end of file
diff --git a/tests/rewrittendir/file1.shtml b/tests/rewrittendir/file1.shtml
new file mode 100644
index 0000000..369cd04
--- /dev/null
+++ b/tests/rewrittendir/file1.shtml
@@ -0,0 +1 @@
+rewrittendir/file1.shtml
\ No newline at end of file
-- 
GitLab