<!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>[415] wp-testcase/test_includes_canonical.php: More Canonicalisation 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>415</dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2011-08-12 09:02:55 +0000 (Fri, 12 Aug 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>More Canonicalisation tests. </pre>

<h3>Modified 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="modfile"><h4>Modified: wp-testcase/test_includes_canonical.php (414 => 415)</h4>
<pre class="diff"><span>
<span class="info">--- wp-testcase/test_includes_canonical.php        2011-08-09 14:59:53 UTC (rev 414)
+++ wp-testcase/test_includes_canonical.php        2011-08-12 09:02:55 UTC (rev 415)
</span><span class="lines">@@ -4,22 +4,25 @@
</span><span class="cx">  * Tests Canonical redirections.
</span><span class="cx">  *
</span><span class="cx">  * 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.
</span><ins>+ *
</ins><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> class WP_Canonical extends _WPDataset2 {
</span><span class="cx"> 
</span><ins>+        // This can be defined in a subclass of this class which contains it's own data() method, those tests will be run against the specified permastruct
+        var $structure = '/%year%/%monthnum%/%day%/%postname%/';
+
</ins><span class="cx">         function SetUp() {
</span><span class="cx">                 parent::SetUp();
</span><span class="cx"> 
</span><del>-                update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');
</del><ins>+                update_option('permalink_structure', $this-&gt;structure);
+                update_option('comments_per_page', 5);
</ins><span class="cx"> 
</span><span class="cx">                 global $wp_rewrite;
</span><del>-                $wp_rewrite-&gt;set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
</del><ins>+                $wp_rewrite-&gt;set_permalink_structure($this-&gt;structure);
</ins><span class="cx">                 create_initial_taxonomies();
</span><del>-                $wp_rewrite-&gt;add_rule('ccr/(.+?)/sort/(asc|desc)', 'index.php?category_name=$matches[1]&amp;order=$matches[2]', 'top'); // ccr = Custom_Cat_Rule
</del><span class="cx"> 
</span><span class="cx">                 $wp_rewrite-&gt;flush_rules();
</span><del>-
</del><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function tearDown() {
</span><span class="lines">@@ -98,12 +101,18 @@
</span><span class="cx">                 return array( /*
</span><span class="cx">                                                  Format: [0]: $test_url,
</span><span class="cx">                                                                 [1]: expected results: Any of the following can be used
</span><del>-                                                                                array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite OR $_GET );
-                                                                                array( expected query vars to be hit )
-                                                                                (string) 'expected redirect url'
</del><ins>+                                                                                array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
+                                                                                array( expected query vars to be set, same as 'qv' above )
+                                                                                (string) expected redirect location
</ins><span class="cx">                                                                 [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
</span><del>-                                                                                */
</del><ins>+                                        */
+
+                                // Please Note: A few test cases are commented out below, Look at the test case following it, in most cases it's simple showing 2 options for the &quot;proper&quot; redirect.
+
</ins><span class="cx">                                 // Categories
</span><ins>+                                array( '?cat=32', '/category/parent/', 15256 ),
+                                array( '?cat=50', '/category/parent/child-1/', 15256 ),
+                                array( '?cat=51', '/category/parent/child-1/child-2/' ), // no children
</ins><span class="cx">                                 array( '/category/uncategorized/', array( 'url' =&gt; '/category/uncategorized/', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized' ) ) ),
</span><span class="cx">                                 array( '/category/uncategorized/page/2/', array( 'url' =&gt; '/category/uncategorized/page/2/', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'paged' =&gt; 2) ) ),
</span><span class="cx">                                 array( '/category/uncategorized/?paged=2', array( 'url' =&gt; '/category/uncategorized/page/2/', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'paged' =&gt; 2) ) ),
</span><span class="lines">@@ -115,14 +124,15 @@
</span><span class="cx"> 
</span><span class="cx">                                 // Categories with Dates
</span><span class="cx">                                 array( '/category/uncategorized/?paged=2&amp;year=2008', array( 'url' =&gt; '/category/uncategorized/page/2/?year=2008', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'paged' =&gt; 2, 'year' =&gt; 2008) ), 17661 ),
</span><del>-                                array( '/2008/04/?cat=1', array( 'url' =&gt; '/2008/04/?cat=1', 'qv' =&gt; array('cat' =&gt; '1', 'year' =&gt; '2008', 'monthnum' =&gt; '04' ) ), 17661 ),
-                                array( '/2008/?category_name=cat-a', array( 'url' =&gt; '/2008/?category_name=cat-a', 'qv' =&gt; array('category_name' =&gt; 'cat-a', 'year' =&gt; '2008' ) ), 17661 ),
-                                array( '/category/uncategorized/?year=2008', array( 'url' =&gt; '/2008/?category_name=uncategorized', 'qv' =&gt; array('category_name' =&gt; 'uncategorized', 'year' =&gt; '2008' ) ), 17661 ),
</del><ins>+//                                array( '/2008/04/?cat=1', array( 'url' =&gt; '/2008/04/?cat=1', 'qv' =&gt; array('cat' =&gt; '1', 'year' =&gt; '2008', 'monthnum' =&gt; '04' ) ), 17661 ),
+                                array( '/2008/04/?cat=1', array( 'url' =&gt; '/category/uncategorized/?year=2008&amp;monthnum=04', 'qv' =&gt; array('category_name' =&gt; 'uncategorized', 'year' =&gt; '2008', 'monthnum' =&gt; '04' ) ), 17661 ),
+//                                array( '/2008/?category_name=cat-a', array( 'url' =&gt; '/2008/?category_name=cat-a', 'qv' =&gt; array('category_name' =&gt; 'cat-a', 'year' =&gt; '2008' ) ) ),
+                                array( '/2008/?category_name=cat-a', array( 'url' =&gt; '/category/cat-a/?year=2008', 'qv' =&gt; array('category_name' =&gt; 'cat-a', 'year' =&gt; '2008' ) ) ),
+//                                array( '/category/uncategorized/?year=2008', array( 'url' =&gt; '/2008/?category_name=uncategorized', 'qv' =&gt; array('category_name' =&gt; 'uncategorized', 'year' =&gt; '2008' ) ), 17661 ),
+                                array( '/category/uncategorized/?year=2008', array( 'url' =&gt; '/category/uncategorized/?year=2008', 'qv' =&gt; array('category_name' =&gt; 'uncategorized', 'year' =&gt; '2008' ) ), 17661 ),
</ins><span class="cx"> 
</span><del>-                                // Custom Rewrite rules leading to Categories
-                                array( '/ccr/uncategorized/sort/asc/', array( 'url' =&gt; '/ccr/uncategorized/sort/asc/', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'order' =&gt; 'asc' ) ) ),
-                                array( '/ccr/uncategorized/sort/desc/', array( 'url' =&gt; '/ccr/uncategorized/sort/desc/', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'order' =&gt; 'desc' ) ) ),
-                                array( '/ccr/uncategorized/sort/desc/?year=2008', array( 'url' =&gt; '/ccr/uncategorized/sort/desc/?year=2008', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'order' =&gt; 'desc', 'year' =&gt; '2008' ) ), 17661 ),
</del><ins>+                                // Tags
+                                array( '?tag_ID=56', '/tag/crushing/'),
</ins><span class="cx"> 
</span><span class="cx">                                 // Pages
</span><span class="cx">                                 array( '/sample%20page/', array( 'url' =&gt; '/sample-page/', 'qv' =&gt; array('pagename' =&gt; 'sample-page', 'page' =&gt; '' ) ), 17653 ), // Page rules always set 'page'
</span><span class="lines">@@ -148,6 +158,11 @@
</span><span class="cx">                                 array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ),
</span><span class="cx">                                 array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ),
</span><span class="cx"> 
</span><ins>+                                // Comments
+                                array( '/2008/03/03/comment-test/?cpage=2', '/2008/03/03/comment-test/comment-page-2/'),
+                                array( '/2008/03/03/comment-test/comment-page-20/', '/2008/03/03/comment-test/comment-page-3/'), // there's only 3 pages
+                                array( '/2008/03/03/comment-test/?cpage=30', '/2008/03/03/comment-test/comment-page-3/'), // there's only 3 pages
+
</ins><span class="cx">                                 // Attachments
</span><span class="cx">                                 array( '/?attachment_id=611', '/2008/06/10/post-format-test-gallery/canola2/' ),
</span><span class="cx">                                 array( '/2008/09/03/images-test/canola2/', '/2008/06/10/post-format-test-gallery/canola2/' ), // Image accessed via incorrect parent
</span><span class="lines">@@ -157,7 +172,7 @@
</span><span class="cx">                                 array( '/?m=2008', '/2008/' ),
</span><span class="cx">                                 array( '/?m=200809', '/2008/09/'),
</span><span class="cx">                                 array( '/?m=20080905', '/2008/09/05/'),
</span><del>-                                array( '/?m=2008095', '/2008/09/'), // Invalid date, /09/ or /09/05/ perhaps?
</del><ins>+                                array( '/?m=2008095', '/2008/09/05/'), // Invalid date, /09/ or /09/05/ perhaps?
</ins><span class="cx"> 
</span><span class="cx">                                 array( '/2008/?day=05', '/2008/?day=05'), // no redirect
</span><span class="cx">                                 array( '/2008/09/?day=05', '/2008/09/05/'),
</span><span class="lines">@@ -167,12 +182,89 @@
</span><span class="cx"> 
</span><span class="cx">                                 // Authors
</span><span class="cx">                                 array( '/?author=3', '/author/chip-bennett/' ),
</span><del>-                                array( '/?author=3&amp;year=2008', '/2008/?author=3'),
-                                array( '/author/chip-bennett/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
</del><ins>+//                                array( '/?author=3&amp;year=2008', '/2008/?author=3'),
+                                array( '/?author=3&amp;year=2008', '/author/chip-bennett/?year=2008'),
+//                                array( '/author/chip-bennett/?year=2008', '/2008/?author=3'), //Either or, see previous testcase.
+                                array( '/author/chip-bennett/?year=2008', '/author/chip-bennett/?year=2008'),
</ins><span class="cx"> 
</span><ins>+                                // Feeds
+                                array( '/?feed=atom', '/feed/atom/' ),
+                                array( '/?feed=rss2', '/feed/' ),
+                                array( '/?feed=comments-rss2', '/comments/feed/'),
+                                array( '/?feed=comments-atom', '/comments/feed/atom/'),
+
+                                // Feeds (per-post)
+                                array( '/2008/03/03/comment-test/?feed=comments-atom', '/2008/03/03/comment-test/feed/atom/'),
+                                array( '/?p=149&amp;feed=comments-atom', '/2008/03/03/comment-test/comments/feed/atom/'),
+                                array( '/2008/03/03/comment-test/?feed=comments-atom', '/2008/03/03/comment-test/comments/feed/atom/' ), // Incorrect URL to an invalid URL?
+
+                                // Misc
+                                array( '/2008%20', '/2008/' ),
+                                array( '//2008////', '/2008/' ),
+
</ins><span class="cx">                                 // Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static)
</span><span class="cx"> 
</span><span class="cx">                                 );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+}
+
+class WP_Canonical_CustomRules extends WP_Canonical {
+        function SetUp() {
+                global $wp_rewrite;
+                parent::SetUp();
+                // Add a custom Rewrite rule to test category redirections.
+                $wp_rewrite-&gt;add_rule('ccr/(.+?)/sort/(asc|desc)', 'index.php?category_name=$matches[1]&amp;order=$matches[2]', 'top'); // ccr = Custom_Cat_Rule
+                $wp_rewrite-&gt;flush_rules();
+        }
+
+        function data() {
+                return array( /*
+                                                 Format: [0]: $test_url,
+                                                                [1]: expected results: Any of the following can be used
+                                                                                array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
+                                                                                array( expected query vars to be set, same as 'qv' above )
+                                                                                (string) expected redirect location
+                                                                [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
+                                        */
+                                // Custom Rewrite rules leading to Categories
+                                array( '/ccr/uncategorized/sort/asc/', array( 'url' =&gt; '/ccr/uncategorized/sort/asc/', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'order' =&gt; 'asc' ) ) ),
+                                array( '/ccr/uncategorized/sort/desc/', array( 'url' =&gt; '/ccr/uncategorized/sort/desc/', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'order' =&gt; 'desc' ) ) ),
+                                array( '/ccr/uncategorized/sort/desc/?year=2008', array( 'url' =&gt; '/ccr/uncategorized/sort/desc/?year=2008', 'qv' =&gt; array( 'category_name' =&gt; 'uncategorized', 'order' =&gt; 'desc', 'year' =&gt; '2008' ) ), 17661 ),
+                                );
+        }
+}
+
+class WP_Canonical_NoRewrite extends WP_Canonical {
+        
+        var $structure = '';
+
+        // These test cases are run against the test handler in WP_Canonical
+
+        function data() {
+                return array( /*
+                                                 Format: [0]: $test_url,
+                                                                [1]: expected results: Any of the following can be used
+                                                                                array( 'url': expected redirection location, 'qv': expected query vars to be set via $_GET );
+                                                                                array( expected query vars to be set, same as 'qv' above )
+                                                                                (string) expected redirect location
+                                                                [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
+                                        */
+
+                                array( '/?p=123', '/?p=123' ),
+
+                                array( '/?p=358 ', array('url' =&gt; '/?p=358',  'qv' =&gt; array('p' =&gt; '358') ) ), // Trailing spaces
+                                array( '/?p=358%20', array('url' =&gt; '/?p=358',  'qv' =&gt; array('p' =&gt; '358') ) ),
+
+                                // These Date rules use ?m= as the redirect as that's the style of Link WordPress creates for date based archives
+                                array( '/?&amp;year=2008', '/?m=2008' ), // Extra &amp;
+                                array( '/?year=2008&amp;cat=', '/?m=2008' ), // Empty qv
+                                array( '/?year=2008&amp;cat=&amp;monthnum=09', '/?m=200809' ), // Empty qv
+                                array( '/?year=2008&amp;monthnum=05', '/?m=200805' ),
+
+                                array( '/?page_id=1', '/?p=1' ), // redirect page_id to p (should cover page_id|p|attachment_id to one another
+                                array( '/?page_id=1&amp;post_type=revision', '/?p=1' ),
+
+                        );
+        }
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>