/** * @covers tfrommen\ThatWasHelpful\Models\Nonce::print_field * @dataProvider provide_get_data * * @param string $response * @param string $action */ public function test_print_field($response, $action) { $testee = new Testee('class_action'); WP_Mock::wpFunction('wp_nonce_field', array('times' => 1, 'args' => array(WP_Mock\Functions::type('string'), WP_Mock\Functions::type('string'), WP_Mock\Functions::type('bool'), TRUE), 'return' => function ($param) { echo $param; })); $this->expectOutputString($response); $testee->print_field($action); $this->assertConditionsMet(); }
/** * Renders the HTML. * * @wp-hook that_was_helpful * * @param int $post_id Optional. Post ID. Defaults to 0. * * @return void */ public function render($post_id = 0) { if (!$post_id) { $post_id = get_the_ID(); if (!$post_id) { return; } } $this->post->set_post_id($post_id); $this->state->set_active(); $data = $this->post->get_data(); ?> <div class="that-was-helpful that-was-helpful--<?php echo $post_id; ?> "> <?php if (is_user_logged_in()) { ?> <form action="" method="POST" class="that-was-helpful__form"> <?php $this->nonce->print_field(); ?> <input type="hidden" name="vote_post" value="<?php echo $post_id; ?> "> <?php $class = 'that-was-helpful__submit button'; if ($data->vote) { $class .= ' active'; $title = $data->titles['active']; } else { $title = $data->titles['vote']; } ?> <input type="submit" name="vote" value="<?php echo esc_attr_x('That was helpful', 'Vote button text', 'that-was-helpful'); ?> " class="<?php echo $class; ?> " title="<?php echo $title; ?> "> </form> <?php } ?> <span class="that-was-helpful__votes"> <?php $string = _nx('%d visitor found that helpful.', '%d visitors found that helpful.', $data->votes, 'Vote description', 'that-was-helpful'); $string = esc_html($string); printf($string, $data->votes); ?> </span> </div> <?php }