Skip to content

Commit

Permalink
Add additional helper function tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHerman committed Jul 21, 2017
1 parent c6168af commit 7dfc9dd
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 additions & 0 deletions tests/test-helper-functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php
/**
* GoDaddy Reseller Store Base Tests
*/

namespace Reseller_Store;

final class TestHelperFunctions extends TestCase {

/**
* Setup.
*/
function setUp() {

parent::setUp();

}

/**
* Test the rstore_prefix() method, without underscores.
*/
public function test_rstore_prefix_no_dashes() {

$string = rstore_prefix( 'string' );

$this->assertEquals( 'rstore_string', $string );

}

/**
* Test the rstore_prefix() method, with dashes.
*/
public function test_rstore_prefix_dashes() {

$string = rstore_prefix( 'string', true );

$this->assertEquals( 'rstore-string', $string );

}

/**
* Test the rstore_is_setup() method.
*/
public function test_rstore_is_setup() {

$this->assertFalse( rstore_is_setup() );

rstore_update_option( 'pl_id', 1234 );

$this->assertTrue( rstore_is_setup() );

}

/**
* Test the rstore_add_to_cart_vars() method.
*/
public function test_rstore_add_to_cart_vars() {

$defaults = [
'id',
'quantity',
'redirect',
'label',
'permalink',
];

$vars = rstore_get_add_to_cart_vars( Tests\Helper::create_product() );

array_map( function( $key ) use ( $vars ) {

$this->assertArrayHasKey( $key, $vars );

}, $defaults );

}

/**
* Test the rstore_get_option() method.
*/
public function test_rstore_get_option() {

$this->assertFalse( rstore_get_option( 'random_option' ) );

$now = strtotime( 'now' );

update_option( 'rstore_last_sync', $now );

$this->assertEquals( $now, rstore_get_option( 'last_sync' ) );

}

/**
* Test the rstore_update_option() method.
*/
public function test_rstore_update_option() {

$this->assertFalse( get_option( 'rstore_random_option' ) );

rstore_update_option( 'random_option', 'string' );

$this->assertEquals( 'string', get_option( 'rstore_random_option' ) );

}

/**
* Test the rstore_delete_option() method.
*/
public function test_rstore_delete_option() {

$this->assertFalse( get_option( 'rstore_random_option' ) );

update_option( 'rstore_random_option', 'string' );

$this->assertEquals( 'string', get_option( 'rstore_random_option' ) );

rstore_delete_option( 'random_option' );

$this->assertFalse( get_option( 'rstore_random_option' ) );

}

/**
* Test the rstore_get_transient() method.
*/
public function test_rstore_get_transient() {

$this->assertFalse( get_transient( 'rstore_products' ) );

// Test a non-existing transient with no callback function.
$rstore_transient = rstore_get_transient( 'products' );

$this->assertNull( $rstore_transient );

// Test a non-existing transient with a callback.
$test_transient = rstore_get_transient( 'products', [], function() {

return 'transient results';

} );

$this->assertEquals( 'transient results', $test_transient );

}

}

0 comments on commit 7dfc9dd

Please sign in to comment.