public function test_customize_meta_boxes()
 {
     $testee = new Testee();
     WP_Mock::wpFunction('remove_meta_box', array('times' => 1, 'args' => array(WP_Mock\Functions::type('string'), WP_Mock\Functions::type('string'), WP_Mock\Functions::type('string'))));
     $testee->customize_meta_boxes();
     $this->assertConditionsMet();
 }
Ejemplo n.º 2
0
 /**
  * @covers       tfrommen\ThatWasHelpful\Models\Nonce::is_valid
  * @dataProvider provide_is_valid_data
  *
  * @param bool   $response
  * @param string $nonce
  * @param string $action
  * @param int    $times
  * @param string $request_value
  */
 public function test_is_valid($response, $nonce, $action, $times, $request_value)
 {
     $class_action = 'class_action';
     $name = 'name';
     $testee = new Testee($class_action, $name);
     $_REQUEST[$name] = $request_value;
     WP_Mock::wpFunction('wp_verify_nonce', array('times' => $times, 'args' => array(WP_Mock\Functions::type('string'), WP_Mock\Functions::type('string')), 'return' => function ($nonce, $nonce_action) use($action, $class_action) {
         return $nonce === 'nonce' && ($nonce_action === 'action' || $nonce_action === $class_action && $action === '');
     }));
     $this->assertSame($response, $testee->is_valid($nonce, $action));
     $this->assertConditionsMet();
 }
 /**
  * @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();
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider provide_get_shortlink_data
  *
  * @param string|bool $response
  * @param string|bool $return
  * @param string      $context
  * @param int         $times
  * @param WP_Post     $post
  *
  * @return void
  */
 public function test_get_shortlink($response, $return, $context, $times, $post)
 {
     $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');
     /** @var tfrommen\ExternalContent\Models\PostType $post_type */
     /** @var tfrommen\ExternalContent\Models\MetaBox $meta_box */
     $testee = new Testee($post_type, $meta_box);
     WP_Mock::wpFunction('get_post', array('times' => $times, 'args' => array(WP_Mock\Functions::type('int')), 'return' => $post));
     $this->assertSame($response, $testee->get_shortlink($return, 42, $context));
     $this->assertConditionsMet();
 }
Ejemplo n.º 5
0
    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();
    }
Ejemplo n.º 6
0
 /**
  * @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();
 }