Plugin Directory

Changeset 1102571


Ignore:
Timestamp:
03/01/2015 03:07:42 PM (11 years ago)
Author:
markzero
Message:

added more tests for optional params and splats

Location:
wp-on-routes/tags/0.2.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-on-routes/tags/0.2.0/README.md

    r1102153 r1102571  
    7676```
    7777
    78 In example above, if you target `/foo/a/b/c/bar/test`, browser will answer with HTTP status 200, with following code, with header and footer included:
     78In example above, if you target `/foo/a/b/c/bar/test`, browser will answer with HTTP status 200, with following code, with header and footer included, only in Firefox browser:
    7979
    8080```
     
    120120
    121121Reference to tests/instructions.txt to read how to test output of your WordPress website.
     122
     123I am using wp-cli to generate testing environment: https://github.com/wp-cli/wp-cli/wiki/Plugin-Unit-Tests.
     124
     125So, before any testing run similar command: `bash bin/install-wp-tests.sh wor_test_db root root localhost latest`.
  • wp-on-routes/tags/0.2.0/tests/instructions.txt

    r1102153 r1102571  
    1 This file contains data for routes to test.
     1This file contains data for routes to test.
     2
    23Place the code below into your theme's functions.php and run phpunit
    3 from inside wp-on-routes plugin directory.
    4 Before you run phpunit make sure to export WOR_SITE variable, e.g. `export WOR_SITE=http://wor.dev` from your command line interface.
     4  from inside wp-on-routes plugin directory.
     5
     6Before you run phpunit make sure to export WOR_SITE variable,
     7  e.g. `export WOR_SITE=http://wor.dev` from your command line interface.
    58
    69
     
    3134      'action' => 'wor_params_intro_2'
    3235    )
     36  ),
     37  array(
     38    'get' => array(
     39      'path' => '/red/green/blue/:param?',
     40      'body' => 'no param'
     41    )
     42  ),
     43  array(
     44    'get' => array(
     45      'path' => '/red/*/blue/:param?',
     46      'body' => 'params & splats',
     47      'action' => 'wor_params_splats'
     48    )
    3349  )
    3450);
     
    4258}
    4359
     60function wor_print_3() {
     61  echo 'Params & splats: ' . $_GET['param'] . ', ' . $_GET['splats'][0];
     62}
     63
    4464add_action('wor_params_intro', 'wor_print');
    4565add_action('wor_params_intro_2', 'wor_print_2');
     66add_action('wor_params_splats', 'wor_print_3');
  • wp-on-routes/tags/0.2.0/tests/test-body.php

    r1102153 r1102571  
    2525    $body = wp_remote_retrieve_body(wp_remote_get("{$home_url}/foo/bar/keyboard/mouse"));
    2626    $this->assertEquals('Params: keyboard, mouse', $body);
     27
     28    // without optional parameter `/red/green/blue/:param?`
     29    $body = wp_remote_retrieve_body(wp_remote_get("{$home_url}/red/green/blue"));
     30    $this->assertEquals('no param', $body);
     31
     32    // with optional parameter and splats `/red/*/blue/:param?`
     33    $body = wp_remote_retrieve_body(wp_remote_get("{$home_url}/red/a/b/c/blue/purple"));
     34    $this->assertEquals('Params & splats: purple, a/b/c', $body);
    2735  }
    2836
Note: See TracChangeset for help on using the changeset viewer.