Proper unit testing in WordPress

I think that what you are looking for would actually technically be called functional testing, integration testing, or acceptance testing. It sounds like you want to test the behavior of the front-end of your website (or the front-end behavior of a plugin or theme), not each unit of the code itself. You might use a … Read more

Vagrant script to setup all the common PHP / WordPress version combinations

On the WordPress side of things, Basic WordPress Vagrant Environment is ready to work with any WordPress version (with a little help). You would still need to find a way to configure the PHP but there is a hint in https://github.com/ideasonpurpose/basic-wordpress-box/blob/master/ansible/roles/php/tasks/php.yml. To use it out of the box; Download or clone the project to wplatest-php55.dev/ … Read more

Show different theme for admin?

I just wrote this quick plugin and it seems to work. Let me know if there is a better way. <?php /* Plugin Name: Theme Switch if Admin Description: Display different theme to user if logged in as admin Author: Kyle Barber */ add_filter(‘template’, ‘change_theme’); add_filter(‘option_template’, ‘change_theme’); add_filter(‘option_stylesheet’, ‘change_theme’); function change_theme($theme) { if ( current_user_can(‘manage_options’) … Read more

Developing, Testing and Releasing

There is a bit of personal philosophy that goes into a deployment workflow. It’s not an easy question to answer outright without knowing your experience with servers and version control, your operating system, hosting, client’s experience and tech culture, etc… Here’s a similar question that has a lot of explanation. For content deployment, you can … Read more

Unit testing in the WordPress backend (is_admin() is true)

According to this test, you use set_current_screen() to navigate to one of these in the setUp method. Alas, none of this is apparent if you look at the tremendously-helpful reference page for get_current_screen()… Example: <?php class AxisSetupTest extends WP_UnitTestCase { /** * @covers AxisWP::__construct */ function test_constructor() { // Assert // Admin $this->assertInternalType(‘integer’, has_action( ‘admin_enqueue_scripts’, … Read more

Unit testing for plugin development

As an ex-software engineer building large business types who landed in an interactive agency let me give you a few thoughts on testing when developing for WordPress: Your Unit Testing should test the smallest amount of behavior that a class can perform. Each class should be able to be tested independently of WordPress. If you … Read more

Testing hooks callback

Test in isolation When developing a plugin, the best way to test it is without loading the WordPress environment. If you write code that can be easily tested without WordPress, your code becomes better. Every component that is unit tested, should be tested in isolation: when you test a class, you only have to test … Read more

Proper way to assert type of variable in Python

The isinstance built-in is the preferred way if you really must, but even better is to remember Python’s motto: “it’s easier to ask forgiveness than permission”!-) (It was actually Grace Murray Hopper’s favorite motto;-). I.e.: This, BTW, lets the function work just fine on Unicode strings — without any extra effort!-)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)