Questions tagged [unit-tests]

Automated tests for the smallest parts of code.

Filter by
Sorted by
Tagged with
0
votes
0answers
13 views

Write test for magic method __clone for plugin development

I implemented the Design Pattern Singleton in my Plugin. and I want to test the magic __clone () method to not allow cloning : /** * Cloning is forbidden due to singleton pattern. */ public function ...
0
votes
1answer
68 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
1answer
31 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
1answer
20 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 { ...
0
votes
0answers
18 views

How to run phpunit test for all files which wordpress plugin have

I have phpunit tests for plugin and it`s works only for main plugin file (screenshot 1). But I need test all files from plugin. For example I have file in "includes" folder (screenshot 2). And I ...
1
vote
0answers
62 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'...
0
votes
1answer
191 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
1answer
58 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
0answers
22 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
0answers
68 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
0answers
39 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
1answer
105 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
0answers
34 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
1answer
207 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
1answer
93 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
2answers
193 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, ...
4
votes
1answer
313 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
1answer
480 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
0answers
62 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
1answer
399 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
2answers
325 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
1answer
488 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 ...
3
votes
1answer
9k 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
2answers
322 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
0answers
379 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
2answers
102 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
2answers
2k 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
1answer
397 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
2answers
100 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
1answer
668 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 ...
3
votes
1answer
331 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
1answer
35 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
1answer
408 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
1answer
444 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
1answer
678 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
2answers
913 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
1answer
627 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
2answers
20k 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
1answer
67 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 ...
6
votes
1answer
1k 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 ...
4
votes
3answers
381 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
76 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
2answers
814 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
1answer
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', ...
3
votes
2answers
455 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 ...
6
votes
1answer
1k 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
1k 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 /private/tmp/wordpress/wp-...
2
votes
2answers
455 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') ->setMethods(...
3
votes
1answer
378 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/ https://make.wordpress.org/core/handbook/automated-...
0
votes
1answer
37 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 ...