Skip to content

Commit

Permalink
Tests MslsOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc committed Nov 1, 2019
1 parent 8767883 commit 60036d1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,5 +3,5 @@ composer.phar
package-lock.json
vendor/
.idea/
node_modules
node_modules/
docs/.vuepress/dist/
111 changes: 59 additions & 52 deletions tests/test-mslsoptions.php
Expand Up @@ -2,95 +2,99 @@

namespace lloc\MslsTests;

use Brain\Monkey\Functions;

use lloc\Msls\MslsOptions;

class WP_Test_MslsOptions extends Msls_UnitTestCase {

function test_is_main_page_method() {
public function get_test() {
Functions\when( 'home_url' )->justReturn( 'https://lloc.de' );
Functions\when( 'get_option' )->justReturn( [] );
Functions\when( 'update_option' )->justReturn( true );

return new MslsOptions();
}

public function test_is_main_page_method() {
Functions\when( 'is_front_page' )->justReturn( true );

$this->assertInternalType( 'boolean', MslsOptions::is_main_page() );
}

function test_is_tax_page_method() {
public function test_is_tax_page_method() {
Functions\when( 'is_category' )->justReturn( true );

$this->assertInternalType( 'boolean', MslsOptions::is_tax_page() );
}

function test_is_query_page_method() {
public function test_is_query_page_method() {
Functions\when( 'is_date' )->justReturn( true );

$this->assertInternalType( 'boolean', MslsOptions::is_query_page() );
}

function test_create_method() {
public function test_create_method() {
Functions\when( 'is_admin' )->justReturn( true );

$this->assertInstanceOf( MslsOptions::class, MslsOptions::create() );
}

function test_instance_method() {
$obj = MslsOptions::instance();
$this->assertInstanceOf( MslsOptions::class, $obj );
return $obj;
}
public function test_get_arg_method() {
$obj = $this->get_test();

function test_get_arg_method( $obj ) {
$this->assertNull( $obj->get_arg( 0 ) );
$this->assertInternalType( 'string', $obj->get_arg( 0, '' ) );
$this->assertInternalType( 'float', $obj->get_arg( 0, 1.1 ) );
$this->assertInternalType( 'array', $obj->get_arg( 0, array() ) );
}

function test_set_method( $obj ) {
function test_set_method() {
$obj = $this->get_test();

$this->assertTrue( $obj->set( array() ) );
$this->assertTrue( $obj->set( array( 'temp' => 'abc' ) ) );
$this->assertFalse( $obj->set( 'Test' ) );
$this->assertFalse( $obj->set( 1 ) );
$this->assertFalse( $obj->set( 1.1 ) );
$this->assertFalse( $obj->set( null ) );
$this->assertFalse( $obj->set( new stdClass() ) );
$this->assertFalse( $obj->set( new \stdClass() ) );
}

/**
* Verify the get_permalink-method
* @depends test_instance_method
*/
function test_get_permalink_method( $obj ) {
function test_get_permalink_method() {
$obj = $this->get_test();

$this->assertInternalType( 'string', $obj->get_permalink( 'de_DE' ) );
}

/**
* Verify the get_postlink-method
* @depends test_instance_method
*/
function test_get_postlink_method( $obj ) {
function test_get_postlink_method() {
$obj = $this->get_test();

$this->assertInternalType( 'string', $obj->get_postlink( 'de_DE' ) );
$this->assertEquals( '', $obj->get_postlink( 'de_DE' ) );
}

/**
* Verify the get_current_link-method
* @depends test_instance_method
*/
function test_get_current_link_method( $obj ) {
function test_get_current_link_method() {
$obj = $this->get_test();

$this->assertInternalType( 'string', $obj->get_current_link() );
}

/**
* Verify the is_excluded-method
* @depends test_instance_method
*/
function test_is_excluded_method( $obj ) {
function test_is_excluded_method() {
$obj = $this->get_test();

$this->assertInternalType( 'boolean', $obj->is_excluded() );
}

/**
* Verify the is_content_filter-method
* @depends test_instance_method
*/
function test_is_content_filter_method( $obj ) {
function test_is_content_filter_method() {
$obj = $this->get_test();

$this->assertInternalType( 'boolean', $obj->is_content_filter() );
}

/**
* Verify the get_order-method
* @depends test_instance_method
*/
function test_get_order_method( $obj ) {
function test_get_order_method() {
$obj = $this->get_test();

$this->assertInternalType( 'string', $obj->get_order() );
}

Expand All @@ -102,19 +106,22 @@ function test_get_url_method( $obj ) {
$this->assertInternalType( 'string', $obj->get_url( '/dev/test' ) );
}

/**
* Verify the get_flag_url-method
* @depends test_instance_method
*/
function test_get_flag_url_method( $obj ) {
function test_get_flag_url_method() {
defined( 'MSLS_PLUGIN__FILE__' ) || define( 'MSLS_PLUGIN__FILE__', '/wp-content/plugins/multisite-language-switcher/multisite-language-switcher.php' );

Functions\when( 'is_admin' )->justReturn( true );
Functions\when( 'plugins_url' )->justReturn( 'https://lloc.de/wp-content/plugins' );

$obj = $this->get_test();

$this->assertInternalType( 'string', $obj->get_flag_url( 'de_DE' ) );
}

/**
* Verify the get_available_languages-method
* @depends test_instance_method
*/
function test_get_available_languages_method( $obj ) {
function test_get_available_languages_method() {
Functions\when( 'get_available_languages' )->justReturn( [] );

$obj = $this->get_test();

$this->assertInternalType( 'array', $obj->get_available_languages() );
}

Expand Down

0 comments on commit 60036d1

Please sign in to comment.