unit testing admin password

The password is … password. You can see that in includes/install.php: wp_install( WP_TESTS_TITLE, ‘admin’, WP_TESTS_EMAIL, true, null, ‘password’ ); The last parameter is the admin password.

Using factory.php outside of trunk for unit testing

The problem is not that the factory class is unavailable, because if that were so you would be getting a fatal “class not found” error. The problem is that you aren’t using your test case properly. This code (and similar) is what is causing the problem: /** * Testing that timeline_express_get_announcement_date() returns what we expect … Read more

How do I mock get_adjacent_post for testing

I used WP_Mock for a long time, until I built Brain Monkey to overcome some problems I found working with it. Using Brain Monkey you can: use Brain\Monkey\Functions; Functions::when(‘get_adjacent_post’)->alias(function() { // mock here… }); or Functions::expect(‘get_adjacent_post’) ->atLeast() ->once() ->with( true, ”, true, ‘topic’ ) ->andReturnUsing(function( $in_same_term, $excluded_terms, $previous ) { // mock here }); This … Read more

struggling to set up WP tests

I have a setup similar to yours, with MAMP. I also have had this problem with PHPUnit. It seems that no matter what you do, PHPUnit does not recognize the include_path from MAMP. You have to add the correct path to the php.ini in /private/etc/.

Writing a unit test for add_menu_page

Rather than worrying about the internal implementation of the menu code and the globals that it uses (there are several beside $menu), I’d use a function like menu_page_url() to check if the page exists. That function will return the URL if the menu is registered, or an empty string if it is not. So you … Read more

WordPress test environment on windows

Your best bet to set up a reusable test environment on a Windows machine is to use Vagrant with a setup such as this. Vagrant will allow you to build portable, reusable virtual machines with a very simple interface which you can use across different operating systems and team members. To set it up, you … Read more

How to set up a user inside unit tests

Just few notes: Looks like you’re doing functional/integration tests rather than unit tests in isolation. Here you’re creating a user, but not setting it as the current one: $user = $this->factory->user->create(); wp_set_current_user( 1 ); You probably want: $user_id = $this->factory->user->create(); wp_set_current_user( $user_id ); Note that cookies aren’t set here, because of: tests_add_filter( ‘send_auth_cookies’, ‘__return_false’ ); … Read more

techhipbettruvabetnorabahisbahis forumuedusedueduedusedusedusedusedusedusedu