Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active April 5, 2022 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/76519a0f6f3f8ad3e77d670104d9e66f to your computer and use it in GitHub Desktop.
Save Shelob9/76519a0f6f3f8ad3e77d670104d9e66f to your computer and use it in GitHub Desktop.
<?php
namespace Something\Tests\Integration;
use PHPUnit\Framework\TestCase;
use Something\Shortcode;
/**
* These tests make sure that nothing is super wrong with our code.
*/
class ShortCodeTest extends \WP_UnitTestCase {
/**
* Make sure the the short code callback outputs HTML when user is logged in.
*
* If this makes no errors, that's good, but still needs manual QA
* If it fails, something is wrong.
*/
public function testShortcodeWorksWithUserLoggedIn()
{
//Create a user
$user = get_user_by('ID',self::factory()->user->create());
//Test shortcode class with logged in user
$obj = new Shortcode($user);
$this->assertNotEmpty( $obj->callback() );
}
/**
* Make sure the the short code callback outputs HTML when user is NOT logged in
*
* If this makes no errors, that's good, but still needs manual QA
* If it fails, something is wrong.
*/
public function testShortcodeWorksWithUserNotLoggedIn()
{
//Fake logged out state
$user = new \WP_User();
$user->ID = 0;
//Create shortcode class, and test output
$obj = new Shortcode($user);
$this->assertNotEmpty( $obj->callback() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment