本文整理汇总了PHP中WP_Mock::onFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Mock::onFilter方法的具体用法?PHP WP_Mock::onFilter怎么用?PHP WP_Mock::onFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Mock
的用法示例。
在下文中一共展示了WP_Mock::onFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetupMetaBoxesNotPostOrPage
public function testSetupMetaBoxesNotPostOrPage()
{
\WP_Mock::wpFunction('add_meta_box', ['times' => 0]);
\WP_Mock::onFilter('dxw_content_review_post_types')->with(['post', 'page'])->reply(['meow']);
\Dxw_Content_Review\Dxw_Content_Review::setup_meta_boxes('post');
\Dxw_Content_Review\Dxw_Content_Review::setup_meta_boxes('page');
}
示例2: test_filtering_staff_details_list
/**
* Testing a custom filter
*/
function test_filtering_staff_details_list()
{
$filtered_array = array('email', 'phone', 'ext', 'coffee type');
\WP_Mock::onFilter('filter_staff_details_list')->with(array('email', 'phone', 'ext'))->reply($filtered_array);
$details = \tenup\demo\get_staff_details_list();
$this->assertSame($filtered_array, $details);
}
示例3: apply_filters
/**
* Call the functions added to a filter hook.
*
* @param string $tag The name of the filter hook.
* @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
* @param mixed $var,... Additional variables passed to the functions hooked to <tt>$tag</tt>.
*
* @return mixed The filtered value after all hooked functions are applied to it.
*/
function apply_filters($tag, $value)
{
$args = func_get_args();
$args = array_slice($args, 1);
$args[0] = $value;
return \WP_Mock::onFilter($tag)->apply($args);
}
示例4: test_get_answer
/**
* Test for the get_answer() method.
*
* @covers HookOracle::get_answer()
*
* @return void
*/
public function test_get_answer()
{
$testee = new HookOracle();
WP_Mock::expectAction('give_answer');
WP_Mock::onFilter('the_answer')->with('42')->reply('4815162342');
$this->assertSame('4815162342', $testee->get_answer(), 'get_answer() should return the expected answer.');
}
示例5: testToString
public function testToString()
{
$layout = new \Dxw\Iguana\Theme\Layout();
$layout->slug = 'slug';
\WP_Mock::onFilter('roots_wrap_slug')->with(['layouts/main.php'])->reply(['layouts/my-layout.php']);
\WP_Mock::wpFunction('locate_template', ['args' => [['layouts/my-layout.php']], 'return' => 'correct output']);
$this->assertEquals('correct output', $layout->__toString());
}
示例6: test_params_filter
/**
*
*/
function test_params_filter()
{
\WP_Mock::onFilter('woocommerce_pos_params')->with('')->reply(array('foo' => 'baz'));
$json = $this->params->toJSON();
$this->assertJson($json);
$data = json_decode($json);
print_r($data);
// WP_Mock doesn't work?? :(
// $this->assertEquals( 'baz', $data->foo );
}
示例7: test_action_plugins_loaded
/**
* Test internationalization integration.
*
* @since 3.2.0
*/
public function test_action_plugins_loaded()
{
// Setup.
\WP_Mock::wpFunction('get_locale', array('times' => 1, 'args' => array(), 'return' => 'en_US'));
\WP_Mock::onFilter('plugin_locale')->with('en_US', 'chriswiegman')->reply('en_US');
\WP_Mock::wpFunction('load_textdomain', array('times' => 1, 'args' => array('chriswiegman', 'lang_dir/chriswiegman/chriswiegman-en_US.mo')));
\WP_Mock::wpFunction('load_plugin_textdomain', array('times' => 1, 'args' => array('chriswiegman', false, CW_PLUGIN_PATH . '/languages/')));
\WP_Mock::expectAction('chriswiegman_plugins_loaded');
// Act.
action_plugins_loaded();
// Verify.
$this->assertConditionsMet();
}
示例8: test_i18n
/**
* Test internationalization integration.
*/
public function test_i18n()
{
// Setup
\WP_Mock::wpFunction('get_locale', array('times' => 1, 'args' => array(), 'return' => 'en_US'));
\WP_Mock::onFilter('plugin_locale')->with('en_US', 'a1dmonitor')->reply('en_US');
\WP_Mock::wpFunction('load_textdomain', array('times' => 1, 'args' => array('a1dmonitor', 'lang_dir/a1dmonitor/a1dmonitor-en_US.mo')));
\WP_Mock::wpFunction('plugin_basename', array('times' => 1, 'args' => array('path'), 'return' => 'path'));
\WP_Mock::wpFunction('load_plugin_textdomain', array('times' => 1, 'args' => array('a1dmonitor', false, 'path/languages/')));
// Act
i18n();
// Verify
$this->assertConditionsMet();
}
示例9: test_get_external_url
/**
* @dataProvider provide_get_external_url_data
*
* @param string $response
* @param string $post_link
* @param WP_Post $post
* @param bool $use_external_url
* @param int $times
* @param string|bool $post_meta
*/
public function test_get_external_url($response, $post_link, $post, $use_external_url, $times, $post_meta)
{
$post_type = Mockery::mock('tfrommen\\ExternalContent\\Models\\PostType');
$post_type->shouldReceive('get_post_type')->andReturn('post_type');
$meta_box = Mockery::mock('tfrommen\\ExternalContent\\Models\\MetaBox');
$meta_box->shouldReceive('get_meta_key')->andReturn('meta_key');
/** @var tfrommen\ExternalContent\Models\PostType $post_type */
/** @var tfrommen\ExternalContent\Models\MetaBox $meta_box */
$testee = new Testee($post_type, $meta_box);
WP_Mock::onFilter('external_content_use_external_url')->with(TRUE)->reply($use_external_url);
WP_Mock::wpFunction('get_post_meta', array('times' => $times, 'args' => array(WP_Mock\Functions::type('int'), WP_Mock\Functions::type('string'), TRUE), 'return' => $post_meta));
$this->assertSame($response, $testee->get_external_url($post_link, $post));
$this->assertConditionsMet();
}
示例10: test_googleadconsole_add_node
public function test_googleadconsole_add_node()
{
$args = array('id' => '', 'title' => 'Google Ad Console', 'href' => 'http://example.com?console');
$expected = array('id' => 'google-ad-console-toggle', 'title' => 'Google Ad Console', 'href' => 'http://example.com?console');
$admin_bar = Mockery::mock('WP_Admin_Bar');
$admin_bar->shouldReceive('add_node')->once()->with($expected);
M::wpFunction('is_admin', array('times' => 1, 'return' => false));
M::wpFunction('googleadconsole_toggle_console_url', array('times' => 1, 'return' => 'http://example.com?console'));
M::wpFunction('get_query_var', array('times' => 1, 'return' => false));
M::wpPassthruFunction('esc_html__');
M::wpPassthruFunction('esc_url');
M::onFilter('googleadconsole_before_add_node')->with($args)->reply(array_merge($args, array('id' => 'google-ad-console-toggle')));
googleadconsole_add_node($admin_bar);
}
示例11: applyFilters
public static function applyFilters($tag, $value)
{
$args = func_get_args();
$args = array_slice($args, 1);
$args[0] = $value;
if (self::$type === HookMock::WP_MOCK) {
return \WP_Mock::onFilter($tag)->apply($args);
}
if (self::$type === HookMock::TRUE_HOOKS) {
$relatedFilters = self::getRelatedHooks($tag, 'filters');
foreach ($relatedFilters as $filter) {
$fn = $filter['fn'];
$acceptedArgs = $filter['args'];
$args[0] = $value;
$value = call_user_func_array($fn, array_slice($args, 0, $acceptedArgs));
}
}
return $value;
}
示例12: test_save
/**
* @dataProvider provide_save_data
*
* @param bool $response
* @param WP_Post $post
* @param bool $is_nonce_valid
* @param bool $is_post_revision
* @param int $user_can_times
* @param bool $user_can
* @param int $update_times
*/
public function test_save($response, WP_Post $post, $is_nonce_valid, $is_post_revision, $user_can_times, $user_can, $update_times)
{
$post_type = Mockery::mock('tfrommen\\ExternalContent\\Models\\PostType');
$post_type->shouldReceive('get_post_type')->andReturn('post_type');
$nonce = Mockery::mock('tfrommen\\ExternalContent\\Models\\Nonce');
$nonce->shouldReceive('is_valid')->andReturn($is_nonce_valid);
$meta_key = 'meta_key';
WP_Mock::onFilter('external_content_meta_key')->with('_external_content')->reply($meta_key);
WP_Mock::wpPassthruFunction('esc_attr', array('times' => 1, 'args' => array(WP_Mock\Functions::type('string'))));
/** @var tfrommen\ExternalContent\Models\PostType $post_type */
/** @var tfrommen\ExternalContent\Models\Nonce $nonce */
$testee = new Testee($post_type, $nonce);
WP_Mock::wpFunction('wp_is_post_revision', array('times' => 1, 'args' => array(WP_Mock\Functions::type('int')), 'return' => $is_post_revision));
WP_Mock::wpFunction('current_user_can', array('times' => $user_can_times, 'args' => array('edit_post', WP_Mock\Functions::type('int')), 'return' => $user_can));
$meta_value = 'meta_value';
$_POST[$meta_key] = $meta_value;
WP_Mock::wpFunction('update_post_meta', array('times' => $update_times, 'args' => array(WP_Mock\Functions::type('int'), $meta_key, $meta_value), 'return' => $response));
/** @var WP_Post $post */
$this->assertSame($response, $testee->save(42, $post));
$this->assertConditionsMet();
}
示例13: test_filters_get_component_presentation_template_path
/**
* Test the filter override for the same method
*/
function test_filters_get_component_presentation_template_path()
{
\WP_Mock::onFilter('component_template')->with(false)->reply('custom-template.php');
$actual = $this->instance->get_component_presentation_template_path(1337);
$this->assertSame('custom-template.php', $actual);
}
示例14: test_get_revision_ids_applies_filter
public function test_get_revision_ids_applies_filter()
{
global $wpdb;
$instance = new RevisionStrike();
$method = new ReflectionMethod($instance, 'get_revision_ids');
$method->setAccessible(true);
$wpdb = Mockery::mock('\\WPDB');
$wpdb->shouldReceive('prepare');
$wpdb->shouldReceive('get_col')->andReturn(array(1, 2, 3));
$wpdb->posts = 'wp_posts';
M::wpPassthruFunction('absint');
M::wpPassthruFunction('esc_sql');
M::onFilter('revisionstrike_get_revision_ids')->with(array(1, 2, 3), 90, 25, array('post'))->reply(array('FILTERED'));
$result = $method->invoke($instance, 90, 25, 'post');
$wpdb = null;
$this->assertEquals(array('FILTERED'), $result);
}
示例15: test_header_meta
/**
* Test header meta injection
*/
public function test_header_meta()
{
// Setup
$meta = '<link type="text/plain" rel="author" href="template_url/humans.txt" />';
\WP_Mock::onFilter('common_humans')->with($meta)->reply($meta);
// Act
ob_start();
header_meta();
$result = ob_get_clean();
// Verify
$this->assertConditionsMet();
$this->assertEquals($meta, $result);
}