public function setUp()
 {
     parent::setUp();
     // We are not testing escaping functions so let them passthrough
     \WP_Mock::wpPassthruFunction('absint');
     \WP_Mock::wpPassthruFunction('esc_url');
 }
 /**
  * @covers       tfrommen\ThatWasHelpful\Models\Nonce::get_field
  * @dataProvider provide_get_data
  *
  * @param string $response
  * @param string $action
  */
 public function test_get_field($response, $action)
 {
     $testee = new Testee('class_action');
     WP_Mock::wpPassthruFunction('wp_nonce_field', array('times' => 1, 'args' => array(WP_Mock\Functions::type('string'), WP_Mock\Functions::type('string'), WP_Mock\Functions::type('bool'), WP_Mock\Functions::type('bool'))));
     $this->assertSame($response, $testee->get_field($action));
     $this->assertConditionsMet();
 }
 public function test_load_message_scenarios()
 {
     $defaults = array('days' => 30, 'limit' => 50);
     $_GET = array('nonce' => true);
     $_POST = $defaults;
     $instance = Mockery::mock('RevisionStrike')->makePartial();
     $instance->shouldReceive('strike')->with($defaults);
     $instance->shouldReceive('get_stats')->times(3)->andReturn(array('count' => 0), array('count' => 5, 'deleted' => 0), array('count' => 5, 'deleted' => 5));
     M::wpFunction('wp_verify_nonce', array('return' => true));
     M::wpFunction('_n', array('times' => 1, 'return' => '%d post revisions'));
     M::wpPassthruFunction('wp_nonce_url');
     M::wpPassthruFunction('submit_button');
     // Pass 1: no revisions found
     ob_start();
     include $this->tools_file;
     $result = ob_get_contents();
     ob_end_clean();
     $this->assertContains('<div class="error"><p>', $result, 'No revisions found did not trigger an error message');
     // Pass 2: revisions found, but nothing deleted
     ob_start();
     include $this->tools_file;
     $result = ob_get_contents();
     ob_end_clean();
     $this->assertContains('<div class="error"><p>', $result, 'The user should be warned when revisions were found be we can\'t delete them');
     // Pass 3: revisions deleted successfully
     ob_start();
     include $this->tools_file;
     $result = ob_get_contents();
     ob_end_clean();
     $this->assertContains('<div class="updated"><p>', $result, 'Notify the user when revisions are deleted');
     $this->assertContains('5 post revisions', $result, 'Display the number of revisions that were removed.');
     unset($_GET, $_POST);
 }
Example #4
0
 /**
  * Invalid items in the getter should return a WP_Error instance
  */
 public function test_getter_exception()
 {
     require_once 'dummy-files/wp_error.php';
     \WP_Mock::wpPassthruFunction('__');
     $context = new WP_TemplateContext();
     $context->invalid;
     $this->assertInstanceOf('WP_Error', $context->invalid);
 }
 public function test_register()
 {
     $testee = new Testee();
     WP_Mock::wpPassthruFunction('_x', array('args' => array(WP_Mock\Functions::type('string'), WP_Mock\Functions::type('string'), 'external-content')));
     WP_Mock::wpPassthruFunction('__', array('args' => array(WP_Mock\Functions::type('string'), 'external-content')));
     WP_Mock::wpFunction('register_post_type', array('times' => 1, 'args' => array('external_content', WP_Mock\Functions::type('array'))));
     $testee->register();
     $this->assertConditionsMet();
 }
Example #6
0
 function testBuildPostTypeExpectsRegisterPostTypeCalledOnce()
 {
     // Arrange
     $PostTypeObj = new PostTypeObj();
     \WP_Mock::wpPassthruFunction('wp_parse_args', array('times' => 1));
     \WP_Mock::wpPassthruFunction('register_post_type', array('times' => 1));
     // Act
     $PostTypeObj->build_post_type('Custom', 'Customs', 'custom', $prefix = 'cfpb_', $args = array('has_archive' => false, 'rewrite' => array('slug' => 'regulations', 'with_front' => false), 'supports' => array('title', 'editor', 'revisions', 'page-attributes', 'custom-fields')));
 }
 /**
  * Test theme setup
  *
  * @since 5.0.0
  */
 function test_init()
 {
     // Setup.
     \WP_Mock::wpPassthruFunction('remove_action');
     \WP_Mock::expectActionAdded('after_setup_theme', 'CW\\Theme\\Functions\\Core\\action_after_setup_theme');
     // Act.
     init();
     // Verify.
     $this->assertConditionsMet();
 }
Example #8
0
 public function test_srcset_replacement_no_protocol_cdn()
 {
     $manager = Base\DomainManager('http://test1.com');
     $manager->add('cdn1.com');
     // Mocks
     M::wpFunction('is_ssl', ['return' => false]);
     M::wpPassthruFunction('esc_url');
     $source = ['url' => 'http://test1.com/image.jpg'];
     $replacer = srcset_replacer('http://test1.com');
     $this->assertEquals('http://cdn1.com/image.jpg', $replacer($source)['url']);
 }
Example #9
0
 protected function plugin()
 {
     // functions used as part of constructor
     Mock::wpPassthruFunction('untrailingslashit');
     Mock::wpFunction('plugin_dir_path', array('args' => bootstrap()->get_framework_path() . '/woocommerce/class-sv-wc-plugin.php', 'return' => bootstrap()->get_framework_path() . '/woocommerce'));
     Mock::wpFunction('is_admin', array('return' => true));
     Mock::wpPassthruFunction('plugin_basename');
     Mock::wpFunction('has_action', array('return' => true));
     $args = array('mock', '7.7.7', 'woocommerce-mock', 'args' => array('dependencies' => 'json', 'function_dependencies' => 'ftp_ssl_connect'));
     return $this->getMockBuilder('SV_WC_Plugin')->setConstructorArgs($args)->getMockForAbstractClass();
 }
 /**
  * @covers tfrommen\ThatWasHelpful\Models\TextDomain::load
  *
  * @return void
  */
 public function test_load()
 {
     $file = '/path/to/file.php';
     $domain = 'text-domain';
     $path = '/domain';
     WP_Mock::wpPassthruFunction('plugin_basename', array('times' => 1, 'args' => array(WP_Mock\Functions::type('string'))));
     $testee = new Testee($file, $domain, $path);
     $path = dirname($file) . $path;
     WP_Mock::wpFunction('load_plugin_textdomain', array('times' => 1, 'args' => array($domain, FALSE, $path)));
     $testee->load();
     $this->assertConditionsMet();
 }
Example #11
0
 public function test_init_widgets()
 {
     $widget = new Widget();
     \WP_Mock::expectActionAdded('widgets_init', array($widget, 'registerWidgets'));
     $widget->init();
     \WP_Mock::wpPassthruFunction('register_widget', array('times' => 1, 'args' => array('Lnh\\Widget\\LastMatch\\LastMatch')));
     \WP_Mock::wpPassthruFunction('register_widget', array('times' => 1, 'args' => array('Lnh\\Widget\\NextMatch\\NextMatch')));
     \WP_Mock::wpPassthruFunction('register_widget', array('times' => 1, 'args' => array('Lnh\\Widget\\Calendar\\Calendar')));
     \WP_Mock::wpPassthruFunction('register_widget', array('times' => 1, 'args' => array('Lnh\\Widget\\Calendar\\Short\\CalendarShort')));
     \WP_Mock::wpPassthruFunction('register_widget', array('times' => 1, 'args' => array('Lnh\\Widget\\Classement\\Classement')));
     $widget->registerWidgets();
 }
 public function test_domain_replacement_mixed()
 {
     $manager = DomainManager('http://test.com');
     $manager->add('https://cdn1.com');
     $original = 'http://test.com/image.png';
     $expected = 'https://cdn1.com/image.png';
     // Mocks
     M::wpFunction('is_ssl', ['return' => false]);
     M::wpPassthruFunction('esc_url');
     // Verify
     $this->assertEquals($expected, $manager->new_url($original));
 }
 function testLoginTransientExpectsTransientSet()
 {
     $user_obj = new StdClass();
     $user_obj->ID = 1;
     $L = new \gboone\LoginLockout();
     \WP_Mock::wpFunction('set_transient', array('times' => 1));
     \WP_Mock::wpPassthruFunction('wp_die');
     $user_id = \WP_Mock::wpFunction('get_user_by', array('times' => 1, 'args' => array('slug', 'user'), 'return' => $user_obj));
     \WP_Mock::wpFunction('get_transient', array('times' => 1, 'return' => false));
     // Act
     $L->login_transient('user');
     // Test fails if set_transient isn't called
 }
Example #14
0
 public function test_save_item_multiple()
 {
     $importer = new Import($this->createItem(10));
     \WP_Mock::wpPassthruFunction('get_posts', array('times' => 1));
     \WP_Mock::wpPassthruFunction('wp_insert_post', array('times' => 1));
     \WP_Mock::wpPassthruFunction('update_post_meta', array('times' => 10));
     $importer->save();
     $importer->setItem($this->createItem(5));
     \WP_Mock::wpPassthruFunction('get_posts', array('times' => 1));
     \WP_Mock::wpPassthruFunction('wp_insert_post', array('times' => 1));
     \WP_Mock::wpPassthruFunction('update_post_meta', array('times' => 5));
     $importer->save();
 }
 /**
  * Test filter_user_contactmethods
  *
  * @since 4.0.0
  */
 public function test_filter_user_contactmethods()
 {
     // Setup.
     \WP_Mock::wpPassthruFunction('esc_html__');
     // Act.
     $contact_methods = filter_user_contactmethods(array());
     // Verify.
     $this->assertTrue(is_array($contact_methods));
     $this->assertArrayHasKey('website_title', $contact_methods);
     $this->assertArrayHasKey('twitter', $contact_methods);
     $this->assertArrayHasKey('facebook', $contact_methods);
     $this->assertArrayHasKey('wordpress', $contact_methods);
     $this->assertArrayHasKey('github', $contact_methods);
 }
    public function test_render()
    {
        $meta_key = '_external_content';
        $model = Mockery::mock('tfrommen\\ExternalContent\\Models\\MetaBox');
        $model->shouldReceive('get_meta_key')->andReturn($meta_key);
        $post_type_slug = 'external_content';
        $post_type = Mockery::mock('tfrommen\\ExternalContent\\Models\\PostType');
        $post_type->shouldReceive('get_post_type')->andReturn($post_type_slug);
        $nonce = Mockery::mock('tfrommen\\ExternalContent\\Models\\Nonce');
        $nonce->shouldReceive('print_field');
        /** @var tfrommen\ExternalContent\Models\MetaBox $model */
        /** @var tfrommen\ExternalContent\Models\PostType $post_type */
        /** @var tfrommen\ExternalContent\Models\Nonce $nonce */
        $testee = new Testee($model, $post_type, $nonce);
        $meta_value = 'http://example.com';
        WP_Mock::wpFunction('get_post_meta', array('times' => 1, 'args' => array(WP_Mock\Functions::type('int'), $meta_key, TRUE), 'return' => $meta_value));
        WP_Mock::wpFunction('esc_html_e', array('times' => 2, 'args' => array(WP_Mock\Functions::type('string'), 'external-content'), 'return' => function () {
            $args = func_get_args();
            echo $args[0];
        }));
        WP_Mock::wpPassthruFunction('esc_attr', array('times' => 1, 'args' => array(WP_Mock\Functions::type('string'))));
        $output = <<<'HTML'
		<p>
			Please enter the URL of the external content.
		</p>
		<table class="form-table">
			<tbody>
			<tr>
				<th scope="row">
					<label for="%1$s">
						External URL
					</label>
				</th>
				<td>
					<input type="url" name="%1$s" class="large-text"
						placeholder="http://example.com" value="%2$s">
				</td>
			</tr>
			</tbody>
		</table>
HTML;
        $output = sprintf($output, $meta_key, $meta_value);
        $this->expectOutputString($output);
        $post = Mockery::mock('WP_Post');
        $post->ID = 42;
        /** @var WP_Post $post */
        $testee->render($post);
        $this->assertConditionsMet();
    }
Example #17
0
 /**
  * Test that the template part was retrieved.
  *
  * @group template
  */
 public function test_template_part_retrieved()
 {
     $model = new \stdClass();
     $model->text = 'template test.';
     $_REQUEST = array('times' => 99);
     WP_Mock::wpFunction('locate_template', array('return_in_order' => array(__DIR__ . '/templates/test-context.php', __DIR__ . '/templates/test-model.php')));
     \WP_Mock::wpPassthruFunction('__');
     ob_start();
     get_template_part('templates/test', 'context', $model);
     $output = ob_get_clean();
     $this->assertEquals('Context claims something happened 99 times!', $output);
     ob_start();
     get_template_part('templates/test', 'model', $model);
     $output = ob_get_clean();
     $this->assertEquals('This is a template test.', $output);
 }
 /**
  * @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();
 }
 public function setUp()
 {
     parent::setUp();
     // Mock the remote request
     \WP_Mock::wpPassthruFunction('absint');
 }
 /**
  * Testing to be sure the the method was called
  *
  * In this case we don't really care what was returned, just that it was called
  */
 function test_registering_the_cpt()
 {
     \WP_Mock::wpPassthruFunction('register_post_type');
     \tenup\demo\action_register_cpt();
 }
 /**
  * Tests that the date() method will draw 12 options
  *
  * @group unstable
  * @group date
  */
 function testDatePrintsAll12Months()
 {
     //arrange
     global $wp_locale;
     $term = new \StdClass();
     $term->name = '';
     $HTML = $this->getMockBuilder('\\CFPB\\Utils\\MetaBox\\HTML')->setMethods(null)->getMock();
     $wp_locale->expects($this->exactly(12))->method('get_month')->will($this->returnValue('month'));
     \WP_Mock::wpPassthruFunction('esc_attr');
     \WP_Mock::wpFunction('has_term', array('return' => true));
     \WP_Mock::wpFunction('get_the_terms', array('return' => array($term)));
     $needle = '<option value="month">month</option><option value="month">month</option>';
     $needle .= '<option value="month">month</option><option value="month">month</option>';
     $needle .= '<option value="month">month</option><option value="month">month</option>';
     $needle .= '<option value="month">month</option><option value="month">month</option>';
     $needle .= '<option value="month">month</option><option value="month">month</option>';
     $needle .= '<option value="month">month</option><option value="month">month</option></select>';
     //act
     ob_start();
     $HTML->date('tax', false, false, '', 12);
     $haystack = ob_get_flush();
     //assert
     $this->assertContains($needle, $haystack);
 }
 public function setUp()
 {
     \WP_Mock::setUp();
     \WP_Mock::wpPassthruFunction('absint');
 }
 public function test_googleadconsole_load_plugin_textdomain()
 {
     M::wpFunction('load_plugin_textdomain', array('times' => 1, 'args' => array('google-ad-console', false, '*')));
     M::wpPassthruFunction('plugin_basename', array('times' => 1));
     googleadconsole_load_plugin_textdomain();
 }
 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);
 }
Example #25
0
 public function test_log_deleted_revision()
 {
     $rs_cli = new RevisionStrikeCLI();
     $wp_cli = WP_CLI::getInstance();
     $wp_cli->shouldReceive('_log')->once();
     M::wpPassthruFunction('esc_html__');
     $rs_cli->log_deleted_revision(4, new \stdClass());
 }
 public function test_sanitize_settings_doesnt_permit_limit_0()
 {
     $instance = Mockery::mock('RevisionStrikeSettings')->makePartial();
     $input = array('limit' => 0);
     $rs = new \stdClass();
     $rs->defaults = array('limit' => 50);
     $property = new ReflectionProperty($instance, 'instance');
     $property->setAccessible(true);
     $property->setValue($instance, $rs);
     M::wpPassthruFunction('absint');
     $this->assertEquals(array('limit' => 50), $instance->sanitize_settings($input));
 }
 /**
  * Let's test to be sure the function is called.
  */
 function test_action_init()
 {
     \WP_Mock::wpPassthruFunction('register_post_type');
     $this->instance->action_init();
 }
 /**
  * Tests whether a meta box can be attached to more than one post type
  *
  * @group stable
  * @group meta_boxes
  * @group generate
  *
  */
 function testArrayinPostTypeExpectsBoxesGenerated()
 {
     // arrange
     $Box = new TestValidBox();
     $Box->post_type = array('post', 'page');
     \WP_Mock::wpFunction('post_type_exists', array('times' => 2, 'return' => true));
     \WP_Mock::wpPassthruFunction('sanitize_key');
     \WP_Mock::wpFunction('add_meta_box', array('times' => 2, 'return' => true));
     // act
     $Box->generate();
     // assert
 }
 public function setUp()
 {
     M::wpPassthruFunction('register_activation_hook');
     M::wpPassthruFunction('register_deactivation_hook');
     parent::setUp();
 }
 /**
  * Setup a Purgely_Related object.
  *
  * Helper function to handle the bootstrapping of all of the wp functions needed to set up the object.
  *
  * @param  string               $type The type of lookup.
  * @param  string               $url  The url for the post.
  * @param  int                  $id   The ID of the post.
  * @param  object               $post The post object.
  * @return Purgely_Related_Urls
  */
 private function setup_object($type, $url, $id, $post)
 {
     \WP_Mock::wpPassthruFunction('absint');
     if ('url' === $type) {
         \WP_Mock::wpFunction('url_to_postid', array('args' => array($url), 'times' => 1, 'return' => $id));
     }
     if (in_array($type, array('id', 'url'))) {
         \WP_Mock::wpFunction('get_post', array('args' => array($id), 'times' => 1, 'return' => $post));
     }
     \WP_Mock::wpFunction('get_permalink', array('args' => array($post), 'times' => 1, 'return' => $url));
 }