Automated tests for the smallest parts of code.

learn more… | top users | synonyms

5
votes
1answer
65 views

Proper unit testing in WordPress

There are different threads available for Unit Testing in WordPress. As far as concern, there should be a proper unit testing for every piece of customization done in WordPress. I have checked couple ...
1
vote
1answer
57 views

Fatal error: Maximum execution time of 60 seconds exceeded in H:\wamp\www\custom\wp-includes\class-wp-http-curl.php

I imported the Theme Unit Test xml file with the wordpress importer. But all of the data is imported as pages. I am following an online tutorial to build a wordpress theme development and I believe ...
1
vote
1answer
21 views

Using factory.php outside of trunk for unit testing

I have written a plugin, and am going through the process of setting up some unit tests for it. Inside of my unit tests I am utilizing the WP_UnitTest_Factory class to help with the process of ...
0
votes
0answers
21 views

WordPress Unit Testing and theme

I just got into WordPress unit testing for a theme and some plugins for a project I inherited that had no tests. I have been using wp-cli and the WP_UnitTestCase which has been working great. I've ...
4
votes
1answer
76 views

Wordpress Unit Testing - Cannot Create Tables

I'm using PHPUnit to Unit Test my WP plugin on top of the WP testing suite. Everything works fine except that when I try to create a table via the setUp method, the table doesn't get created. Here's ...
3
votes
1answer
40 views

Unit testing to simulate the loop

How do you construct unit tests with PHPUnit and the WordPress test framework that simulate being in the loop? For instance, if I want to test a function that is only able to be called in the loop ...
1
vote
0answers
12 views

Is there a way to mock update_option for unit testing?

I'm currently building some unit tests, and have just started playing around with WP_Mock. I'd like to test a function that fetches the site description; I want to test if it responds as expected when ...
1
vote
1answer
24 views

PHPUnit test plugin activation

I'm trying to test if my plugin activates properly with PHPUnit. I have used boilerplate structure generated on this site and added this test: class PluginTest extends WP_UnitTestCase { function ...
5
votes
1answer
73 views

When unit testing a plugin, does the plugin need to be in the wp-content/plugins directory of the WordPress tests install?

I'm currently setting up unit testing for my plugin. In my tests/phpunit/bootstrap.php file I have: require_once $wp_tests_dir . '/includes/functions.php'; tests_add_filter( 'muplugins_loaded', ...
3
votes
2answers
80 views

Using Travis CI to run unit tests and running phpunit locally [closed]

Is there a difference between Travis CI running my PHPUnit tests and me using the WP-CLI to generate unit test files and running phpunit locally? I'm wondering if the duplicate effort is necessary or ...
1
vote
1answer
88 views

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

I've asked this on IRC, Twitter, Slack — am utterly astonished by how difficult it is to locate the answer to this: I have a bunch of plugin code that only runs when is_admin() returns true, i.e., ...
2
votes
1answer
204 views

DataBase connection problem with PHPUnit and WordPress

I'm trying to run PHPUnit to unittest a WordPress plugin, but the error below keeps showing up. Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in ...
2
votes
2answers
99 views

How do I mock get_adjacent_post for testing

I'm trying to mock get_adjacent_post for unit testing but I'm not sure how to mock global function in PHPUnit $badCode = $this->getMockBuilder('get_adjacent_post') ...
0
votes
0answers
137 views

WP Unit tests error: WP_UnitTestCase not found

I installed PHPUnit, checked out the WordPress tests repository and set up the tests configuration. But when I try to run the unit tests on my test files (e.g: phpunit test-test.php), I get the ...
1
vote
1answer
69 views

How can I properly set up dependencies in automated testing?

I'm trying to set up automated tests for my WP- and BP-dependent plugin, as described in: https://codex.buddypress.org/developer/automated-testing/ ...
0
votes
1answer
16 views

Unregister Settings Error

Is it possible to unregister or unset an error that has been added using add_settings_error? What I am trying to do is run some unit tests on my settings validation function, but I'd like to reset any ...
0
votes
1answer
30 views

How can I link tests to GitHub issues?

I'm trying to run WordPress automated tests as described in this article. Predictably, I've been getting a lot of skipped tests marked S, because, according to the article, "this usually means that ...
5
votes
1answer
193 views

Plugin Unit Test for Table and Option Creation

I've started to incorporate unit testing in my build. I have a class that creates a database table and a database version option. I have no idea how to test if the table and option are being created. ...
0
votes
1answer
102 views

How exactly *does* unit testing work for themes?

As the majority of material on unit testing focuses on plugin development rather than theme development, I've hit a stumbling block when trying it out for myself. I've installed PHPUnit, grabbed the ...
1
vote
1answer
257 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.
1
vote
0answers
76 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
75 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() ) { ...
16
votes
1answer
2k 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 ...
1
vote
1answer
291 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
26 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
308 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', ...
1
vote
2answers
142 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
36 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
45 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
166 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
116 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: ...
3
votes
1answer
1k 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 ...
4
votes
1answer
795 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 ...
11
votes
2answers
2k 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
5answers
2k 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
102 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 ...
2
votes
2answers
1k 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
309 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
262 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
142 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
782 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
2k 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
29 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
1k 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
209 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
224 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
116 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 ...
4
votes
2answers
442 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
175 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 ...
5
votes
1answer
422 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?