Skip to content

Commit

Permalink
Fix register-wp-admin-settings.php tests based on recent changes to h…
Browse files Browse the repository at this point in the history
…andle email registration
  • Loading branch information
justinshreve committed Sep 8, 2016
1 parent a36b25a commit 6fafbe8
Showing 1 changed file with 48 additions and 34 deletions.
82 changes: 48 additions & 34 deletions tests/unit-tests/settings/register-wp-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public function setUp() {
* @covers WC_Register_WP_Admin_Settings::__construct
*/
public function test_constructor() {
$settings = new WC_Register_WP_Admin_Settings( $this->page );
$settings = new WC_Register_WP_Admin_Settings( $this->page, 'page' );

$this->assertEquals( has_filter( 'woocommerce_settings_groups', array( $settings, 'register_group' ) ), 10 );
$this->assertEquals( has_filter( 'woocommerce_settings-' . $this->page->get_id(), array( $settings, 'register_settings' ) ), 10 );
$this->assertEquals( has_filter( 'woocommerce_settings_groups', array( $settings, 'register_page_group' ) ), 10 );
$this->assertEquals( has_filter( 'woocommerce_settings-' . $this->page->get_id(), array( $settings, 'register_page_settings' ) ), 10 );
}

/**
* @since 2.7.0
* @covers WC_Register_WP_Admin_Settings::register_group
*/
public function test_register_group() {
$settings = new WC_Register_WP_Admin_Settings( $this->page );
$settings = new WC_Register_WP_Admin_Settings( $this->page, 'page' );

$existing = array(
'id' => 'existing-id',
Expand All @@ -66,7 +66,7 @@ public function test_register_group() {
'label' => $this->page->get_label(),
),
);
$actual = $settings->register_group( $initial );
$actual = $settings->register_page_group( $initial );

$this->assertEquals( $expected, $actual );
}
Expand All @@ -79,19 +79,21 @@ public function register_setting_provider() {
// No "id" case
array(
array(
'type' => 'some-type-with-no-id',
'type' => 'some-type-with-no-id',
'option_key' => '',
),
false,
),
// All optional properties except 'desc_tip'
array(
array(
'id' => 'setting-id',
'type' => 'select',
'title' => 'Setting Name',
'desc' => 'Setting Description',
'default' => 'one',
'options' => array( 'one', 'two' ),
'id' => 'setting-id',
'type' => 'select',
'title' => 'Setting Name',
'desc' => 'Setting Description',
'default' => 'one',
'options' => array( 'one', 'two' ),
'option_key' => '',
),
array(
'id' => 'setting-id',
Expand All @@ -100,53 +102,60 @@ public function register_setting_provider() {
'description' => 'Setting Description',
'default' => 'one',
'options' => array( 'one', 'two' ),
'option_key' => '',
),
),
// Boolean 'desc_tip' defaulting to 'desc' value
array(
array(
'id' => 'setting-id',
'type' => 'select',
'title' => 'Setting Name',
'desc' => 'Setting Description',
'desc_tip' => true,
'id' => 'setting-id',
'type' => 'select',
'title' => 'Setting Name',
'desc' => 'Setting Description',
'desc_tip' => true,
'option_key' => '',
),
array(
'id' => 'setting-id',
'type' => 'select',
'label' => 'Setting Name',
'description' => 'Setting Description',
'tip' => 'Setting Description',
'option_key' => '',
),
),
// String 'desc_tip'
array(
array(
'id' => 'setting-id',
'type' => 'select',
'title' => 'Setting Name',
'desc' => 'Setting Description',
'desc_tip' => 'Setting Tip',
'id' => 'setting-id',
'type' => 'select',
'title' => 'Setting Name',
'desc' => 'Setting Description',
'desc_tip' => 'Setting Tip',
'option_key' => '',
),
array(
'id' => 'setting-id',
'type' => 'select',
'label' => 'Setting Name',
'description' => 'Setting Description',
'tip' => 'Setting Tip',
'option_key' => '',
),
),
// Empty 'title' and 'desc'
array(
array(
'id' => 'setting-id',
'type' => 'select',
'id' => 'setting-id',
'type' => 'select',
'option_key' => '',
),
array(
'id' => 'setting-id',
'type' => 'select',
'label' => '',
'description' => '',
'option_key' => '',
),
),
);
Expand All @@ -158,7 +167,7 @@ public function register_setting_provider() {
* @covers WC_Register_WP_Admin_Settings::register_setting
*/
public function test_register_setting( $input, $expected ) {
$settings = new WC_Register_WP_Admin_Settings( $this->page );
$settings = new WC_Register_WP_Admin_Settings( $this->page, 'page' );

$actual = $settings->register_setting( $input );

Expand All @@ -181,10 +190,10 @@ public function test_register_settings_one_section() {
->with( $this->equalTo( 0 ) )
->will( $this->returnValue( array() ) );

$settings = new WC_Register_WP_Admin_Settings( $this->page );
$settings = new WC_Register_WP_Admin_Settings( $this->page, 'page' );

$expected = array();
$actual = $settings->register_settings( array() );
$actual = $settings->register_page_settings( array() );

$this->assertEquals( $expected, $actual );
}
Expand All @@ -201,15 +210,18 @@ public function test_register_settings() {

$settings = array(
array(
'id' => 'setting-1',
'type' => 'text',
'id' => 'setting-1',
'type' => 'text',
'option_key' => '',
),
array(
'type' => 'no-id',
'type' => 'no-id',
'option_key' => '',
),
array(
'id' => 'setting-2',
'type' => 'textarea',
'id' => 'setting-2',
'type' => 'textarea',
'option_key' => '',
),
);

Expand All @@ -218,23 +230,25 @@ public function test_register_settings() {
->method( 'get_settings' )
->will( $this->returnValue( $settings ) );

$settings = new WC_Register_WP_Admin_Settings( $this->page );
$settings = new WC_Register_WP_Admin_Settings( $this->page, 'page' );

$expected = array(
array(
'id' => 'setting-1',
'type' => 'text',
'label' => '',
'description' => '',
'option_key' => 'setting-1',
),
array(
'id' => 'setting-2',
'type' => 'textarea',
'label' => '',
'description' => '',
'option_key' => 'setting-2',
),
);
$actual = $settings->register_settings( array() );
$actual = $settings->register_page_settings( array() );

$this->assertEquals( $expected, $actual );
}
Expand Down

0 comments on commit 6fafbe8

Please sign in to comment.