[wp-trac] [WordPress Trac] #21271: Make admin backend unit-tests friendly

WordPress Trac wp-trac at lists.automattic.com
Sat Jul 14 14:19:21 UTC 2012


#21271: Make admin backend unit-tests friendly
----------------------------+--------------------------------------
 Reporter:  sirzooro        |      Owner:
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:  3.4.1
 Severity:  normal          |   Keywords:  needs-patch dev-feedback
----------------------------+--------------------------------------
 Recently I started writing unit tests for my plugins. Beside tests focused
 on functionality (where I directly call my plugin functions) I write some
 basic integrations tests, which should test that WordPress will call my
 function, pass data in expected format and recognize data returned from
 it. For frontend it is quite easy - theme API is well-defined, so I can
 write something like this:
 {{{
 public function test_something() {
         // add new post
         $post_id = wp_insert_post( array( ... ) );
         $this->assertGreaterThan( 0, $post_id );

         // go to post page
         $this->go_to( get_permalink( $post_id ) );

         // main loop
         $checked_post = false;
         while ( have_posts() ) {
                 the_post();
                 if ( $post_id == get_the_ID() ) {
                         $checked_post = true;

                         // test that content is modified
                         ob_start();
                         the_content();
                         $result = ob_get_clean();
                         $this->assertEquals( '...', $result );
                 }
         }

         // make sure test above was executed
         $this->assertTrue( $checked_post );
 }
 }}}
 Unfortunately this is not true for admin backend - there most of code is
 written directly at file level (not in functions and classes), so I would
 need to either duplicate this code in my tests (bad approach, because
 would have to monitor original code for changes), or test using whole file
 (either load it directly or use Selenium) - in this case test would be
 more complicated.

 Therefore I logged this ticket, to start discussion how we can perform
 refactoring of admin backend to make it more tests-friendly, and how to
 test it more thoroughly. Most probably we would also need to modify the
 testing framework (e.g. introduce new `admin_go_to()` method).

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21271>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list