Make WordPress Core

Ticket #17653: 17653-tests.patch

File 17653-tests.patch, 1.7 KB (added by jared_smith, 11 years ago)

Unit tests

  • tests/phpunit/tests/canonical/spacesHyphens.php

     
     1<?php
     2
     3require_once dirname( dirname( __FILE__ ) ) . '/canonical.php';
     4
     5/**
     6 * @group canonical
     7 * @group rewrite
     8 * @group query
     9 */
     10class Tests_Canonical_NoRewrite extends Tests_Canonical {
     11        var $structure = '';
     12
     13        var $canonical_post_id = 0;
     14
     15        function setUp() {
     16                parent::setUp();
     17
     18                $this->author = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) );
     19
     20
     21                $post = array(
     22                        'post_author' => $this->author->ID,
     23                        'post_status' => 'publish',
     24                        'post_content' => rand_str(),
     25                        'post_title' => "Hello World",
     26                        'post_name' => "hello-world",
     27                );
     28
     29                // insert a post
     30                $this->ID = wp_insert_post($post);
     31                echo "\nInserted post $this->ID\n";
     32                $this->canonical_post_id = $this->ID;
     33                echo get_permalink($this->ID);
     34
     35        }
     36
     37        function tearDown() {
     38                parent::tearDown();
     39                wp_delete_post($this->canonical_post_id);
     40        }
     41
     42        function data() {
     43                /* Format:
     44                 * [0]: $test_url,
     45                 * [1]: expected results: Any of the following can be used
     46                 *      array( 'url': expected redirection location, 'qv': expected query vars to be set via the rewrite AND $_GET );
     47                 *      array( expected query vars to be set, same as 'qv' above )
     48                 *      (string) expected redirect location
     49                 * [3]: (optional) The ticket the test refers to, Can be skipped if unknown.
     50                 */
     51                update_option( 'permalink_structure', '/%postname%/');
     52
     53                return array(
     54                        array( '/hello%20world/', '/hello-world/' ),
     55                        array( '/hello%20%20world/', '/hello-world/' ),
     56                );
     57
     58        }
     59
     60}