Questions tagged [unit-tests]
Automated tests for the smallest parts of code.
91
questions
0
votes
0
answers
30
views
Jest Unit tests for High order component containing Block Editor
everyone!
I created High order component HOC which adds additional panel to Advanced section at the right sidebar
Something like this:
import React from 'react'
import {InspectorAdvancedControls} ...
0
votes
0
answers
20
views
Testing Plugin - Install plugin dependencies in testing enviroment
I have a problem with a unit test. My plugin depends on the Timber plugin for rendering a Twig template.
But when I need to run the unit test with WordPress testing enviroment, I can't install ...
1
vote
1
answer
169
views
PHPUnit Plugin Integration Tests: Getting wordpress-tests-lib PHP into IDE (VS Code)
So I've managed to follow the instructions to get the "Plugin Integration Tests" set up using wp-cli and the install-wp-tests.sh script as described in the handbook article:
https://make....
2
votes
0
answers
447
views
Testing custom API endpoint with class dependency
Sorry I feel like really stuck here.
I have a plugin introducing a new Rest API controller (WP_REST_Controller) with basically a single endpoint which uses a separate class as a client to fetch some ...
0
votes
1
answer
244
views
Mocking WP_CLI static methods in unit tests
I'm writing unit tests (not integration) for a lib I'm working on. There, we created some WP-CLI commands that I'd like to test. Most of them are just renaming things, copying and pasting things over ...
0
votes
1
answer
64
views
How can I enable IDE integration (autocomplete) for WordPress test suite
When testing a theme or plugin, you can use WP-CLI to scaffold the test suite setup, wp scaffold plugin-test plugin.
So is there a good way to integrate an editor/IDE (VS Code in my case) so that ...
2
votes
1
answer
222
views
How to verify meta box is registered in Unit Testing?
I am currently doing TDD with WordPress, in the PHPUnit I need to test if the meta box is actually registered on a method call, I could not find any function in WordPress to do that, so I was trying ...
1
vote
1
answer
484
views
How do I phpunit test a post output process?
I like to know how to test the html output of a post. Like WP would output it on the frontend in reality.
My specific case at this point is to test oembed caching as I want to test re-caching. AFAIK ...
0
votes
1
answer
469
views
Why is one phpunit test throwing an error on one class when all other classes are similar without error?
I'm working on the Liquid Messages plugin. There are some basic PHPUnit tests existing for it and when I run phpunit all pass except for one. It errors out:
There was 1 error:
1) GCS_Async_Test::...
0
votes
1
answer
384
views
PHPUnit Testing and woocommerce Constant
I tried to perform a test on the WC_VERSION constant.
The main class :
class WC_Custom_Variable_Products_Dependencies {
/** minimum WooCommerce version required by this plugin */
const ...
0
votes
1
answer
426
views
Unit Testing action hook
I want to perform unit tests on a Class, my goal is: I want to check if the plugin is activated or not by using the function: is_plugin_active
class WC_Custom_Variable_Products_Dependencies {
...
1
vote
0
answers
319
views
Coverage in integration tests
EDIT:
I've created the mwe as a small test plugin: https://github.com/dingo-d/test-plugin
Original question:
I'm writing tests for my plugin and one thing makes no sense to me and I'm not sure if I'm ...
1
vote
2
answers
2k
views
Unit Test in Wordpress
I work in wordpress with a lot of classes that use wordpress functions and I'd like make unit tests for them. The problem I found is that phpunit doesn't recognize wordpress functions and the tests ...
0
votes
1
answer
424
views
Wordpress and Wordpress-test-lib not getting added to tmp folder
I’ve installed the wpcli and php unit testing to my imac and the wordpress and wordpress-test-lib files were added to my tmp folder as they should have. I used this to install the setup.
bash bin/...
1
vote
0
answers
47
views
Underscores Theme Unit Testing - Catching Untitled Posts
Wordpress 5.0.3 | Underscores Theme
I'm unit testing a theme I based on underscores using the wptest.io xml.
Underscores does not gracefully catch untitled posts. There is no title in either ...
0
votes
0
answers
172
views
Integration test - remove the mu plugins in the test
As a recurring theme these past few questions I asked, I'm doing integration testing and want to check the activate static method that gets called in my register_activation_hook in the main plugin ...
1
vote
0
answers
79
views
Am I testing this right?
Since I need to have 100% test coverage for the client, I'm writing integration and unit tests in my plugin. And I have a method in a class that is hooked to admin_menu hook, which adds submenu.
...
1
vote
1
answer
254
views
Extending WP_UnitTestCase without any Tests
I want to add some logging to an extension of WP_UnitTestCase.
Like this:
class MZMBO_UnitTestCase extends WP_UnitTestCase
{
public function el($message){
file_put_contents('./log_'.date(...
4
votes
0
answers
49
views
What is the best way to do unit tests for your plugin in 2018 [closed]
I´m making a wordpress plugin with PHPStorm. This plugin contains a load of files with addons as well and it´s the time to use unit tests to check up before each commit in my github project.
I took a ...
0
votes
2
answers
550
views
Write integration test for rest_pre_serve_request
I have a method that is hooked to the rest_api_init
/**
* Set allowed headers for the rest request
*/
public function set_allowed_rest_headers() {
remove_filter( '...
0
votes
1
answer
422
views
Integration tests test script enqueue/register fails
This question is related to this SO post
I'm testing a plugin, and in it I have
public function enqueue_scripts() {
$main_style = 'public/scripts/application.js';
wp_register_script( '...
3
votes
2
answers
697
views
Revert WordPress default options after a PHPUnit test has run
tl;dr: is there a way to make changes to WordPress options during a PHPUnit test suite execution, and have the changes reverted to the WordPress defaults before the next test suite is executed, ...
7
votes
1
answer
2k
views
How to set up a user inside unit tests
I want to test some methods in my plugin, and some of them required user to be logged in.
I searched everywhere but found nothing of use.
I need to test a method that takes in logged in session ...
2
votes
1
answer
942
views
Why is WP_Mock not used instead of WP_UnitTestCase for writing unit tests by most plugins?
For writing unit-tests, why do most plugins use WP_UnitTestCase instead of popular libraries like WP_Mock?
The reason I am asking this is because WP_UnitTestCase doesn't seem to be a unit test case ...
1
vote
0
answers
118
views
Unit testing a plugin with a theme dependency
I wrote a plugin that adds functionality to load a content block (which is a page), and then passes it to a template part, which I did to avoid overloading the core WP global post. I'm trying to unit ...
1
vote
1
answer
723
views
How to retain table data in wordpress phpunit tests
I was wondering is there a way that phpunit for woprdress do not delete any data which i created during test?
0
votes
2
answers
661
views
PHPUnit via WP-CLI: Warning: Cannot modify header information ... bootstrap.php:68
I'm trying to setup unit tests for a plugin I am developing. I just followed the steps at... https://make.wordpress.org/cli/handbook/plugin-unit-tests/
However, when I run phpunit I get the ...
5
votes
1
answer
947
views
Writing a unit test for add_menu_page
I am writing a few unit tests for a plugin that I have developed. However I seem to be hung up on testing one (seemingly) simple piece of code.
In the plugin I've written I have registered an admin ...
11
votes
1
answer
30k
views
Access post from post id in URL
I'm doing unit tests for my plugin, and in my unit test, I check some basic things such as posting a custom post type. My script can create new post, and I can retrieve the ID of the posted item (I'm ...
3
votes
2
answers
814
views
Is there any way of of making an admin-ajax request without the use of die()?
Pretty much what the title says.
I have a custom plugin written, that relies on the use of admin-ajax to handle various forms and actions. That's all working fine, however as the various functions ...
3
votes
0
answers
725
views
Setting Up PHPUnit tests for WP development on Windows
I've been following the instructions in this article to try to set up some testing.
I got as far as this instruction bash bin/install-wp-tests.sh wordpress_test root 'mypass' localhost latest before ...
0
votes
2
answers
146
views
Installing WordPress Theme Unit Data
I'm following the "Building Themes from Scratch Using Underscores (2016)" tutorial on Lynda.com and at around 00:35 he suggests downloading the Theme Unit Test Data from WordPress. I've downloaded the ...
1
vote
2
answers
3k
views
What is the best way to create a factory for unit test objects?
I am trying to learn TDD and am struggling with creating factories for custom objects. For instance, if I have a custom user type and all users of that type must have a specific capability, it's ...
0
votes
1
answer
863
views
How to do an unit test for the admin dashboard
I am trying to do unit test on codeception with wp-browser for a wordpress plugin based on a boilerplate.
The problem that is in this line of code I initialize the class for admin only when is not an ...
4
votes
2
answers
157
views
What areas to Unit test while building a plugin?
I am a plugin developer with absolutely no industry experience. I have created a simple plugin to add multiple contributors to a post through metabox.
I searched through tons of websites and I got to ...
1
vote
1
answer
2k
views
Error when setting up phpunit tests with wp-cli scaffold
I am trying to figure out the setup for unit tests for wordpress plugins. I am using Ubuntu. So far I have:
Local WordPress Installation
WP-CLI up and running
Installed phpunit
used wp scaffold ...
4
votes
1
answer
621
views
Using wp_mail during an integration test
I'm working on some tests for WordPress, and I discovered that WordPress' PHPUnit automatically captures and doesn't send emails (using MockPHPMailer) when I try to use wp_mail.
I've looked, but I ...
0
votes
1
answer
45
views
Set up PHPUnit with WordPress: The WordPress tests are 3 - 4 years old; does it matter?
I'm trying to set up PHPUnit with WordPress, and the tutorial I found tells me to download this repository so that I can bootstrap the WordPress environment to run my tests. The only issue I have is ...
7
votes
1
answer
1k
views
Unit tests - Dealing with dependencies
This might be seen as a corollary of Testing hooks callback.
The issue:
I want to test a class which creates a new instance of a My_Notice class defined outside the plugin (let's call it the "Main ...
0
votes
1
answer
584
views
Unable to find PHPUnit code coverage stats
Where should I check for the code coverage stats when using PHPUnit for WordPress?
My WordPress setup:
I have setup WordPress using VVV and my testing suite includes PHPUnit and WP-CLI.
How I ...
7
votes
1
answer
936
views
Writing test cases for a WordPress Plugin that has translations
What is my aim?
I'm looking forward to write test cases for the available translations of a WordPress plugin.
My approach:
I have setup WordPress using VVV and my testing suite includes PHPUnit and ...
3
votes
2
answers
2k
views
Install and load additional plugins when running unit tests
I want to write unit tests for a plugin. I have used WP-CLI to scaffold the test WordPress instance and can successfully run tests.
The plugin I'm writing unit tests for is a site specific plugin ...
8
votes
1
answer
905
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 ...
2
votes
2
answers
21k
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 ...
2
votes
1
answer
124
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 ...
8
votes
2
answers
2k
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 ...
5
votes
3
answers
638
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
0
answers
150
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
2
answers
2k
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 ...
7
votes
1
answer
1k
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', ...