2017-12-14 11:57:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Testing WC_Widget functionality.
|
|
|
|
*
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Tests\Widgets
|
2017-12-14 11:57:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for testing WC_Widget functionality.
|
|
|
|
*/
|
|
|
|
class WC_Tests_Widget extends WC_Unit_Test_Case {
|
|
|
|
/**
|
|
|
|
* Test intance creation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function test_instance() {
|
2020-08-26 21:46:44 +00:00
|
|
|
require_once __DIR__ . '/class-dummy-widget.php';
|
2017-12-14 11:57:53 +00:00
|
|
|
$dummy_widget = new Dummy_Widget();
|
|
|
|
$this->assertTrue( property_exists( $dummy_widget, 'widget_id' ) );
|
|
|
|
}
|
|
|
|
|
2017-12-18 13:58:40 +00:00
|
|
|
/**
|
|
|
|
* Test widget caching.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-12-14 11:57:53 +00:00
|
|
|
public function test_caching() {
|
|
|
|
global $wp_widget_factory;
|
2020-08-26 21:46:44 +00:00
|
|
|
require_once __DIR__ . '/class-dummy-widget.php';
|
2017-12-14 11:57:53 +00:00
|
|
|
register_widget( 'Dummy_Widget' );
|
|
|
|
|
|
|
|
$dummy_widget = $wp_widget_factory->widgets['Dummy_Widget'];
|
2017-12-18 13:58:40 +00:00
|
|
|
|
|
|
|
// Uncached widget.
|
|
|
|
ob_start();
|
|
|
|
$cache_hit = $dummy_widget->get_cached_widget( array( 'widget_id' => $dummy_widget->widget_id ) );
|
2019-05-01 22:05:00 +00:00
|
|
|
$output = ob_get_clean();
|
2017-12-18 13:58:40 +00:00
|
|
|
$this->assertFalse( $cache_hit );
|
|
|
|
$this->assertEmpty( $output );
|
|
|
|
|
|
|
|
// Render widget to prime the cache.
|
|
|
|
ob_start();
|
2017-12-14 11:57:53 +00:00
|
|
|
$dummy_widget->widget( array( 'widget_id' => $dummy_widget->widget_id ), array() );
|
2017-12-18 13:58:40 +00:00
|
|
|
ob_get_clean();
|
|
|
|
|
|
|
|
// Cached widget.
|
|
|
|
ob_start();
|
|
|
|
$cache_hit = $dummy_widget->get_cached_widget( array( 'widget_id' => $dummy_widget->widget_id ) );
|
2019-05-01 22:05:00 +00:00
|
|
|
$output = ob_get_clean();
|
2017-12-18 13:58:40 +00:00
|
|
|
$this->assertTrue( $cache_hit );
|
|
|
|
$this->assertEquals( 'Dummy', $output );
|
2017-12-14 11:57:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 13:58:40 +00:00
|
|
|
/**
|
|
|
|
* Test widget form.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-12-14 11:57:53 +00:00
|
|
|
public function test_form() {
|
|
|
|
global $wp_widget_factory;
|
2020-08-26 21:46:44 +00:00
|
|
|
require_once __DIR__ . '/class-dummy-widget.php';
|
2017-12-14 11:57:53 +00:00
|
|
|
register_widget( 'Dummy_Widget' );
|
|
|
|
$dummy_widget = $wp_widget_factory->widgets['Dummy_Widget'];
|
|
|
|
$this->assertEmpty( $dummy_widget->form( array( 'widget_id' => $dummy_widget->widget_id ) ) );
|
|
|
|
}
|
|
|
|
}
|