<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[362] wp-testcase/test_includes_canonical.php: Add first wave of Canonical tests</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd>362</dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2011-06-02 11:33:55 +0000 (Thu, 02 Jun 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add first wave of Canonical tests</pre>
<h3>Added Paths</h3>
<ul>
<li><a href="#wptestcasetest_includes_canonicalphp">wp-testcase/test_includes_canonical.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="wptestcasetest_includes_canonicalphp"></a>
<div class="addfile"><h4>Added: wp-testcase/test_includes_canonical.php (0 => 362)</h4>
<pre class="diff"><span>
<span class="info">--- wp-testcase/test_includes_canonical.php         (rev 0)
+++ wp-testcase/test_includes_canonical.php        2011-06-02 11:33:55 UTC (rev 362)
</span><span class="lines">@@ -0,0 +1,105 @@
</span><ins>+<?php
+
+/*
+ * Tests Canonical redirections.
+ *
+ * In the process of doing so, it also tests WP, WP_Rewrite and WP_Query, A fail here may show a bug in any one of these areas.
+ */
+
+class WP_Canonical extends _WPDataset2 {
+
+        function SetUp() {
+                parent::SetUp();
+
+                update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');
+
+                global $wp_rewrite;
+                $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
+                create_initial_taxonomies();
+                $wp_rewrite->flush_rules();
+                
+        }
+
+        function tearDown() {
+                parent::tearDown();
+
+                delete_option('permalink_structure');
+
+                global $wp_rewrite;
+                $wp_rewrite->set_permalink_structure('');
+                $wp_rewrite->flush_rules();
+
+                $_GET = array();
+        }
+
+        // URL's are relative to the site "front", ie. /category/uncategorized/ instead of http://site.../category..
+        // Return url's are full url's with the prepended home.
+        function get_canonical($test_url) {
+                $can_url = redirect_canonical( get_option('home') . $test_url, false);
+                if ( empty($can_url) )
+                        return get_option('home') . $test_url; // No redirect will take place for this request
+
+                return $can_url;
+        }
+
+        /**
+         * @dataProvider data
+         */
+        function test($test_url, $expected, $ticket = 0) {
+                if ( $ticket )
+                        $this->knownWPBug($ticket);
+
+                $this->http( get_option('home') . $test_url );
+
+                // Does the redirect match what's expected?
+                $can_url = $this->get_canonical( $test_url );
+                $parsed_can_url = parse_url($can_url);
+
+                // Just test the Path and Query if present
+                $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : '') );
+                
+                // request url is correct, Next, "make" that the request and check the query is correct
+                $this->http( $can_url );
+                
+                // Are all query vars accounted for, And correct?
+                global $wp;
+
+                $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars);
+                if ( !empty($parsed_can_url['query']) ) {
+                        parse_str($parsed_can_url['query'], $_qv);
+
+                        // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite)
+                        $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET' );
+                        
+                        $query_vars = array_merge($query_vars, $_qv);
+                }
+
+                $this->assertEquals( $expected['qv'], $query_vars );
+
+        }
+
+        function data() {
+                return array( /* Format: [0]: $test_url, [1]: expected results: array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite OR $_GET ); */
+                                // Categories
+                                array( '/category/uncategorized/', array( 'url' => '/category/uncategorized/', 'qv' => array( 'category_name' => 'uncategorized' ) ) ),
+                                array( '/category/uncategorized/page/2/', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
+                                array( '/category/uncategorized/?paged=2', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ) ),
+                                array( '/category/uncategorized/?paged=2&category_name=uncategorized', array( 'url' => '/category/uncategorized/page/2/', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2) ), 17174 ),
+                                
+                                // Categories & Intersections with other vars
+                                array( '/category/uncategorized/?tag=post-formats', array( 'url' => '/category/uncategorized/?tag=post-formats', 'qv' => array('category_name' => 'uncategorized', 'tag' => 'post-formats') ) ),
+                                array( '/?category_name=cat-a,cat-b', array( 'url' => '/?category_name=cat-a,cat-b', 'qv' => array('category_name' => 'cat-a,cat-b' ) ) ),
+                                
+                                // Categories with Dates
+                                array( '/category/uncategorized/?paged=2&year=2008', array( 'url' => '/category/uncategorized/page/2/?year=2008', 'qv' => array( 'category_name' => 'uncategorized', 'paged' => 2, 'year' => 2008) ), 17661 ),
+                                array( '/2008/04/?cat=1', array( 'url' => '/2008/04/?cat=1', 'qv' => array('cat' => '1', 'year' => '2008', 'monthnum' => '04' ) ), 17661 ),
+                                array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ), 17661 ),
+                                
+                                // Pages
+                                array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page' ) ), 17653 ),
+                                array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page' ) ), 14773 ),
+                                
+                                );
+        }
+
+}
</ins><span class="cx">\ No newline at end of file
</span><span class="cx">Property changes on: wp-testcase/test_includes_canonical.php
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
</div>
</body>
</html>