Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Expand more tests around functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0ttkclark committed Sep 1, 2021
1 parent 6c83cf5 commit 3d35b93
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 218 deletions.
3 changes: 3 additions & 0 deletions tests/_support/TestCases/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function setUp() : void {
// Do anything we need to do to set up the environment for these tests.

$this->factory()->pmpro_level = new PMPro_LevelFactory();

// Reset the user to visitor before each test.
wp_set_current_user( 0 );
}

/**
Expand Down
218 changes: 0 additions & 218 deletions tests/to-migrate/includes/test-functions.php

This file was deleted.

59 changes: 59 additions & 0 deletions tests/wpunit/functions/Levels/ChangeMembershipLevelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace PMPro\Tests\Functions\Levels;

use PMPro\Test_Support\Factories\PMPro_LevelFactory;
use PMPro\Test_Support\TestCases\TestCase;

/**
* @group pmpro-functions
* @group pmpro-levels
*/
class ChangeMembershipLevelTest extends TestCase {

/**
* @covers ::pmpro_changeMembershipLevel()
*/
public function test_pmpro_changeMembershipLevel_is_false_with_empty_level_and_invalid_user() {
$this->assertFalse( pmpro_changeMembershipLevel( null ) );
$this->assertFalse( pmpro_changeMembershipLevel( 0 ) );
$this->assertFalse( pmpro_changeMembershipLevel( '' ) );
$this->assertFalse( pmpro_changeMembershipLevel( [] ) );
}

/**
* @covers ::pmpro_changeMembershipLevel()
*/
public function test_pmpro_changeMembershipLevel_is_null_with_invalid_level_and_no_user_and_valid_current_user() {
$user_id = $this->factory->user->create();

wp_set_current_user( $user_id );

$this->assertNull( pmpro_changeMembershipLevel( null ) );
$this->assertNull( pmpro_changeMembershipLevel( 0 ) );
$this->assertNull( pmpro_changeMembershipLevel( '' ) );
$this->assertNull( pmpro_changeMembershipLevel( [] ) );
}

/**
* @covers ::pmpro_changeMembershipLevel()
*/
public function test_pmpro_changeMembershipLevel_is_null_with_invalid_level_and_valid_user() {
$user_id = $this->factory()->user->create();

$this->assertNull( pmpro_changeMembershipLevel( null, $user_id ) );
$this->assertNull( pmpro_changeMembershipLevel( 0, $user_id ) );
$this->assertNull( pmpro_changeMembershipLevel( '', $user_id ) );
$this->assertNull( pmpro_changeMembershipLevel( [], $user_id ) );
}

/**
* @covers ::pmpro_changeMembershipLevel()
*/
public function test_pmpro_changeMembershipLevel_is_true_with_valid_level_and_valid_user() {
$level_id = $this->factory()->pmpro_level->create();
$user_id = $this->factory()->user->create();

$this->assertTrue( pmpro_changeMembershipLevel( $level_id, $user_id ) );
}
}
24 changes: 24 additions & 0 deletions tests/wpunit/functions/Levels/GetMembershipLevelsForUserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace PMPro\Tests\Functions\Levels;

use PMPro\Test_Support\Factories\PMPro_LevelFactory;
use PMPro\Test_Support\TestCases\TestCase;

/**
* @group pmpro-functions
* @group pmpro-levels
*/
class GetMembershipLevelsForUserTest extends TestCase {

/**
* @covers ::pmpro_getMembershipLevelsForUser()
*
* @param null $user_id
* @param bool $include_inactive
* @param bool $expects
*/
public function test_pmpro_getMembershipLevelsForUser( $user_id = null, $include_inactive = false, $expects = false ) {
$this->assertFalse( pmpro_getMembershipLevelsForUser( null, false ) );
}
}
Loading

0 comments on commit 3d35b93

Please sign in to comment.