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');
 }
 /**
  * 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);
 }
Example #3
0
 /**
  * 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);
 }
 /**
  * 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.');
 }
Example #5
0
 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());
 }
 /**
  *
  */
 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 );
 }
 /**
  * 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();
 }
 /**
  * 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();
 }
 /**
  * @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();
 }
 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);
 }
Example #11
0
 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;
 }
 /**
  * @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();
 }
 /**
  * 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);
 }
 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);
 }
 /**
  * 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);
 }
Example #16
0
 /**
  * @covers ::output
  */
 public function test_output()
 {
     $atts = array('test' => 'expected');
     $inner_content = 'test';
     $expected_content = $atts['test'];
     $actual_content = $this->shortcode->output($atts);
     $this->assertEquals($actual_content, $expected_content, 'Shortcode output wrapper returns the callback output.');
     $expected_content = $atts['test'] . $inner_content;
     $actual_content = $this->shortcode->output($atts, $inner_content);
     $this->assertEquals($actual_content, $expected_content, 'Shortcode output wrapper returns the callback output with content.');
     $unfiltered_content = $atts['test'] . $inner_content;
     $expected_content = 'filtered';
     \WP_Mock::onFilter('syllables/shortcode/output')->with($unfiltered_content, $atts, $inner_content, $this->tag)->reply($expected_content);
     $actual_content = $this->shortcode->output($atts, $inner_content, $this->tag);
     $this->assertEquals($actual_content, $expected_content, 'Shortcode output wrapper filters the callback output.');
 }
 public function test_launch_on_shutdown()
 {
     $async = $this->getMockAsync('Async', array('prepare_data', 'create_async_nonce'));
     $async->shouldReceive('prepare_data')->andReturn(array());
     $async->shouldReceive('create_async_nonce')->andReturn('asdf');
     WP_Mock::wpFunction('maybe_serialize', array('return' => function ($thing) {
         return is_scalar($thing) ? $thing : serialize($thing);
     }));
     $_COOKIE = array('_some_cookie' => 'Value', 'foo' => 'bar', 'random' => rand(0, 999999), 'array' => array('not', 'scalar'));
     $cookie_header = '';
     array_walk($_COOKIE, function ($value, $key) use(&$cookie_header) {
         if (!empty($cookie_header)) {
             $cookie_header .= '; ';
         }
         if (!is_scalar($value)) {
             $value = serialize($value);
         }
         $cookie_header .= "{$key}=" . urlencode($value);
     });
     $verify_ssl = (bool) rand(0, 1);
     WP_Mock::onFilter('https_local_ssl_verify')->with(true)->reply($verify_ssl);
     WP_Mock::wpFunction('admin_url', array('times' => 1, 'args' => array('admin-post.php'), 'return' => $url = 'https://tctechcrunch2011.wordpress.com/wp-admin/admin-post.php'));
     WP_Mock::wpFunction('wp_remote_post', array('times' => 1, 'args' => array($url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => $verify_ssl, 'body' => array('action' => 'wp_async_async', '_nonce' => 'asdf'), 'headers' => array('cookie' => $cookie_header)))));
     /** @var Async $async */
     $async->launch();
     // to set up body data, etc.
     $async->launch_on_shutdown();
     $this->assertConditionsMet();
 }
 function testRAMPPermissionsExpectsDegraded()
 {
     \WP_Mock::onFilter('ramp-user-access-base')->with($this->anything())->reply('publish_pages');
 }