Tagged Questions

Automated tests for the smallest parts of code.

learn more… | top users | synonyms

1
vote
1answer
14 views

How to add an image for unit testing?

I have to test the function where it calls wp_get_attachment_image_src. How do I add an image for testing, because right now if I call this method it returns false.
0
votes
0answers
12 views

What is WP_MULTISITE and why it causes WP_UnitTestCase to create 404 page?

I'm using WP_UnitTestCase to create a post for unit test. I'm using WP_MULTISITE=1 on my CI and it causes create_post to create post type 404. $post_id = ...
1
vote
0answers
43 views

What make possible unit test plugins?

This is more a theory related question. I'm not looking at the practical ways to do this, as I can find plenty of example (official and not), which however does not explain how it is possible to ...
4
votes
1answer
26 views

How to create a test that calls is_front_page in phpunit?

I'm using WP_UnitTestCase but in my code I have this condition. is_front_page which I'm not sure how to simulate that in PHPUnit This is the piece of code that I have elseif ( is_front_page() ) { ...
7
votes
1answer
354 views

Testing hooks callback

I'm developing a plugin using TDD and one thing that i completely fail to test are... hooks. I mean OK, i can test hook callback, but how could I test if a hook actually trigger (both custom hooks ...
0
votes
1answer
27 views

How to initialize something in unit test before the init hook being called?

I've a simple PHP Unit written for WordPress and want the initialize code before the main 'init' action being called from the plugin I want to test, e.g. class MyPlugin_Test_Example extends ...
0
votes
0answers
19 views

Unit Test ignores stubbed method second time around in a dataProvider

I am writing a sample unit test that checks a title of a post for a token and if it exists add the post to a category. https://gist.github.com/matstars/bebedbacedd7a85d8dc7 In my test for this I am ...
2
votes
1answer
60 views

How to properly test a method that is called by an action hook

The constructor in my class adds an action to the 'init' action hook: class My_Custom_Post_Type { function __construct( $type ) { $this->type = $type; add_action( 'init', ...
0
votes
2answers
69 views

How to cancel Wordpress' action/filter when using OOP with anonymous callback

Most of the wordpress plugins I found is functions based, for example, the offical akismet plugin function akismet_init() { global $wpcom_api_key, $akismet_api_host, $akismet_api_port; // ...
2
votes
0answers
23 views

Theme unit test data Foreign fonts come in garbled on my machine

Having just tried out the Theme Unit Test Data from the WordPress.org Codex, I noticed that some of the body text doesn't import properly on my set up which is a Mac running Mavericks. The effect is ...
1
vote
0answers
30 views

WordPress Automatic Testing Probelm

After much trial and error. I've managed to get the automatic testing setup and running. I'm running a test on a plugin that has no code. It's just the plugin header. Just to make sure everything is ...
1
vote
1answer
63 views

WordPress function gives different results outside vs inside PHPUnit test

I've been working very hard to get PHPUnit to play nice with WordPress (with the help of this, this, this, this, and this), and I think I've gotten pretty close. The code I run directly before my ...
1
vote
1answer
38 views

Using My Own Classes On Wp Unit Tests

(I'm trying to solve style problems of code samples) I'm developing a theme but I have some classes which developed for this theme. I want to run unit tests on my theme. I've followed this steps: ...
0
votes
0answers
40 views

Wordpress Unit Testing cleaning up hooks and filters

Using Wordpress' unit testing suite has been going quite well, and it's nice the WP_UnitTestCase takes care of cleaning up table data after each unit test. But one thing that doesn't seem to be ...
3
votes
1answer
700 views

PHPUnit testing WordPress Plugin

Using answers on this site and from other resources, I have started writing my next plugin using PHPUnit tests and the WordPress test environment. Distilling down what I have in my plugin's ...
3
votes
1answer
242 views

Wordpress test environment on windows

I'm new to TDD and want to set up a test environment for my wordpress plugin. I was able to find a sample plugin from wp-cli with the very useful script. It was very easy to write the first test ...
7
votes
2answers
542 views

Where can I find documentation for the WP_UnitTestCase factory classes?

In recent versions WP_UnitTestCase has included a $factory property. For example: $post = $this->factory->post->create(); Where can I find documentation on this useful feature?
4
votes
4answers
837 views

How do I mock HTTP requests for PHPUnit?

I'm writing a plugin that makes requests to the Facebook graph API. As I don't want my unit tests to actually make these requests, how would I overcome this? My method calls both wp_remote_get and ...
2
votes
2answers
66 views

how to test a theme upgrade

Is there a way to test run a theme through the automatic updater? We have a theme where a version will introduce new functionality which might break existing themes. I would like to check previous ...
0
votes
2answers
315 views

Implement phpunit testing on a plugin

I've just finished writing a WordPress plugin implementing shortcode tag based autocompletion based on values retrieved from a database given an id set on a cookie. The plugin has a variety of ...
3
votes
2answers
172 views

struggling to set up WP tests

I want to contribute to a guys plugin (TimberWp). I'd like to do it with tests. his plugin has a test dir that looks just like the wp-cli scaffolded dir. all v standard. Iv'e managed to get as ...
5
votes
0answers
227 views

Can’t get the phpunit core test for WordPress to work [closed]

I’m trying to set up the test for the WordPress core to make sure that the plugin I’m developing doesn't break anything. But I’m having a problem which I really have no idea how to fix. I downloaded ...
1
vote
1answer
82 views

how to set context in Wordpress for unit testing

I have created a wordpress plugin which converts shortcodes to content based on the entry saved on the dataase: global $wpdb; $post_id = get_the_ID(); $post_content = get_the_content(); ...
8
votes
1answer
305 views

WordPress Themes and PHP unit

Is there any examples of using PHP unit tests with WordPress themes, seems a lot of blogs out there on the subject are out dated as the core unit tests are apart of trac, yet last night - I pulled ...
0
votes
2answers
719 views

How to import Theme Unit Test on localhost

I am a total beginner with WP and struggle to import this xml file. Tools->Import->WordPress and here I am asked for Hostname, FTP Username, FTP Password and Connection Type. I am on local mashine... ...
1
vote
0answers
22 views

Error Testing create_empty_blog() via PHPUnit + Unit Tests

I have been reading up on TDD for a little while, and now have a multisite plugin to 'test' it out on.. At this stage I am a little unsure whether the error is within the Unit Tests, my tests, my ...
3
votes
1answer
495 views

Why Can't PHPUnit UnitTest My Wordpress Website

I have been researching this issue for days and although many people ask this question I never found a clear and concise answer. I am running: PHP Unit: Version 3.7.21 WordPress: Version 3.5.1 OS: ...
6
votes
1answer
184 views

How to write testable classes in Wordpress

I'm currently doing some modifications on the Wordpress plugin that I created in order to make it testable. The problem is I don't know which methods am I suppose to write tests for. I have methods ...
1
vote
1answer
133 views

Unit testing wordpress plugins with plugin options

I'm new with unit testing in Wordpress. I managed to setup the unit testing environment using PHP Unit and Wordpress tests but I am having trouble accessing the plugin options that I've set in the ...
2
votes
1answer
72 views

unit testing admin password

I'm writing up unit tests for my plugin and I need a logged in user to test, but I can't find the admin password anywhere. Does anybody know what the default admin password is? I'm extending the ...
2
votes
2answers
234 views

Plugin development with unit tests

One of the things that my plugin does is creates a number of SQL tables as part of a versioning function (that is run under the admin_init hook as I couldn't find a better wordpress way of doing ...
2
votes
1answer
52 views

Unit Testing a Plugin functionality with cron

I'm currently on the process of unit testing a plugin using the Wordpress unit testing framework. In one of the functions to be tested,it will send mails to users in a periodic time interval so it ...
4
votes
1answer
187 views

Can I simulate a user being logged in from a WP_UnitTestCase?

I have some logic in my code that's based on whether or not the user is logged in. How do I test it from my WP_UnitTestCase?
3
votes
1answer
398 views

WP_UnitTestCase missing?

I was looking at tests for wordpress and some, if not all the classes have WP_UnitTestCase but I cannot find the class, why do I care? I have downloaded The most up to date version of this from github ...