Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Do you have file to test WP stuff?

  1. #1
    Rarst's Avatar
    Rarst is offline Big Tipper
    Join Date
    Jul 2009
    Posts
    322

    Default Do you have file to test WP stuff?

    Just interested. I have not seen many tutorials or suggestions about WP testbeds. I assume people stick with whatever they are used to in programming.

    Here is file I came up with and keep as test.php to quickly throw some code there and see how it works.

    PHP Code:
    <?php
    //PHP report errors
        
    error_reporting(E_ALL E_STRICT);
    //WP debug
        
    define('WP_DEBUG'true);
    //WP log queries
        
    define('SAVEQUERIES'true);    
    //WP init
        
    require('wp-blog-header.php');
    //WP admin only
        
    if (!current_user_can('administrator')) wp_die('Boo!');
    //WP includes
        //include_once(ABSPATH.WPINC.'/.php'); 
        
    include_once(ABSPATH.WPINC.'/print_nice.php'); 

    //code goes here


    //WP performance
        //echo get_num_queries().' queries in '.timer_stop(0,3).' seconds<br />';
    //WP queries
        //preprint($wpdb->queries);
    //WP cron
        //preprint(_get_cron_array());
    //WP active plugins
        //preprint(get_option('active_plugins'));
    //WP hooked functions, from http://www.wprecipes.com/?p=1830
        //list_hooked_functions();
    //PHP extensions
        //preprint(get_loaded_extensions());
    //PHP configuration
        //phpinfo();

    function preprint($array) {echo '<pre>'.print_r($array,true).'</pre>';}
    ?>
    Do you use something like this? Know any things worth adding here?
    Last edited by Rarst; 02-19-2010 at 04:08 AM. Reason: updates to code
    Rarst.net - cynical thoughts on software and web (and sometimes WP) | @Rarst | I seem to be non-GPL-compliant person. Beware my poisonous thoughts.

  2. #2
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    I'm normally testing locally and don't need wp-blog-header.php, so I tend to use nothing more than the following along with whatever code it is that I'm testing:

    PHP Code:
    <?php 

    require( '../../../wp-load.php' ); 

    // Some other stuff here

    ?>

  3. #3
    BinaryMoon's Avatar
    BinaryMoon is offline Hello World
    Join Date
    Jun 2009
    Posts
    56

    Default

    I've been thinking about this as well. I'd be interested to know how much testing goes into WordPress outside of sending things to beta testers.

    It'd be great if there was some kind of unit testing done, and also if there was some sort of framework to test theme functionality, especially if you have a more complex theme (framework)

  4. #4
    Rarst's Avatar
    Rarst is offline Big Tipper
    Join Date
    Jul 2009
    Posts
    322

    Default

    @BinaryMoon

    On topic of unit tests for WP take a look at this:
    http://westi.wordpress.com/2009/12/2...ss-a-check-up/
    Rarst.net - cynical thoughts on software and web (and sometimes WP) | @Rarst | I seem to be non-GPL-compliant person. Beware my poisonous thoughts.

  5. #5
    mfields's Avatar
    mfields is offline Here For The Peanuts
    Join Date
    Nov 2009
    Location
    Portland, OR
    Posts
    168

    Default

    @Rarst - Interesting topic - thanks for posting this. For testing, I have a version of WordPress installed on localhost in a folder named after it's version 2.9, 2.9.1, 2.1.2, etc. And usually just write code in functions.php or the theme file that I want to target. I never thought to setup a testing script like this.

    BTW - we have very similar debug functions. Here's mine:

    PHP Code:
    if( !function_exists'pr) ) {
        function 
    pr$var ) {
            print 
    '<pre>' print_r$vartrue ) . '</pre>';
        }


  6. #6
    Rarst's Avatar
    Rarst is offline Big Tipper
    Join Date
    Jul 2009
    Posts
    322

    Default

    @mfields

    I often need to understand wth is going on inside specific function or hook and it is easier when theme doesn't get in the way. :) It also simplifies related constants (instead flipping them in wp-config all the time).

    There are quite a few plugins that add extensive debug info to posts, I am thinking about hooking one to my test.php but excluding from blog itself so it doesn't get in the way there.
    Rarst.net - cynical thoughts on software and web (and sometimes WP) | @Rarst | I seem to be non-GPL-compliant person. Beware my poisonous thoughts.

  7. #7
    johnbintz is offline Hello World
    Join Date
    Oct 2009
    Location
    Baltimore, MD
    Posts
    2

    Default

    Quote Originally Posted by BinaryMoon View Post
    It'd be great if there was some kind of unit testing done, and also if there was some sort of framework to test theme functionality, especially if you have a more complex theme (framework)
    Two subjects dear to my own heart. I have two projects going on right now that, while still in sporadic development only when I need new features, provide both a WordPress simulation framework for use with PHPUnit/SimpleTest, and a rich environment for creating test WP data quickly and easily, which, when combined with Selenium, allows for all sorts of easy test automation for both themes and plugins:

    Caveat emptor, of course, but they work well enough for me.

  8. #8
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    594

    Default

    Quote Originally Posted by johnbintz View Post
    Two subjects dear to my own heart. I have two projects going on right now that, while still in sporadic development only when I need new features, provide both a WordPress simulation framework for use with PHPUnit/SimpleTest, and a rich environment for creating test WP data quickly and easily, which, when combined with Selenium, allows for all sorts of easy test automation for both themes and plugins:

    Caveat emptor, of course, but they work well enough for me.
    Thats so cool. Will need to check that out. I'm working on a PHP WP equivalent of FxCop. It checks for security flaws, coding standards and more.

  9. #9
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

    Default

    Testing schmesting.

    I just write my code correctly the first time. Much easier.

  10. #10
    Rarst's Avatar
    Rarst is offline Big Tipper
    Join Date
    Jul 2009
    Posts
    322

    Default

    One more line I missed (spent some time with docs yesterday):

    PHP Code:
    //WP debug
        
    define('WP_DEBUG'true); 
    Highlighted several notices that don't show up with regular settings for me.
    Rarst.net - cynical thoughts on software and web (and sometimes WP) | @Rarst | I seem to be non-GPL-compliant person. Beware my poisonous thoughts.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •