I am developing a plugin to simplify the addition of rewrites to Wordpress. I have started using the Wordpress test suite. Essentially I have a class RewriteManager to which you can add Rewrite objects. One of the methods for Rewrite is isThisRewrite() which queries itself to determine if the url called relates to this rewrite:
// add the rewrite to the manager
$manager->addRewrite(new Rewrite(array(
"path" => "test/path/([^/]+)/([^/]+)/?$",
"querystring" => "index.php?rewrite=test&test=$matches[1]&test2=$matches[2]"
);
// start the manager - takes care of adding the rules, query vars etc...
$manager->start();
What I am looking to do in my unit test is to add a rewrite rule, navigate to the relevant url and then query the query_vars to ensure that the rule has been added correctly. I have tried the following:
$this->manager->addRewrite($this->actionRewrite);
$this->manager->start();
flush_rewrite_rules();
$this->go_to("/test/path/hello/there");
At this point I expect $wp_query to show test and test2 to show relevantly populated query_vars but there are no query vars at all. Is there a specific way of testing custom rewrites?