public function test_textarea_wysiwyg() { $textarea = new Textarea('mon_textarea', null, "mon_textarea_id", array('wysiwyg' => true)); \WP_Mock::expectActionAdded('admin_print_footer_scripts', array($textarea, 'addEditorTinymce'), 99); $html = $textarea->getDisplay(); $this->assertRegExp('/<textarea(. *)+><\\/textarea>/', $html); }
public function testRegister() { $layoutRegister = new \Dxw\Iguana\Theme\LayoutRegister($this->getHelpers()); $this->assertInstanceOf(\Dxw\Iguana\Registerable::class, $layoutRegister); \WP_Mock::expectFilterAdded('template_include', [\Dxw\Iguana\Theme\Layout::class, 'apply'], 99); $layoutRegister->register(); }
/** * Tests hooking the template loader to the WordPress template loading filters * with a priority. * * @covers ::ready * * @dataProvider loader_provider */ public function test_ready_priority(Loader $loader) { $priority = rand(11, 99); \WP_Mock::expectFilterAdded('template_include', array($loader, 'filter'), $priority); $loader->ready($priority); $this->assertHooksAdded(); }
public function react($args) { \WP_Mock::invokeAction($this->name); $arg_num = count($args); if (0 === $arg_num) { if (!isset($this->processors['argsnull'])) { return; } $this->processors['argsnull']->react(); } else { $processors = $this->processors; for ($i = 0; $i < $arg_num - 1; $i++) { $arg = $this->safe_offset($args[$i]); if (!isset($processors[$arg])) { return; } $processors = $processors[$arg]; } $arg = $this->safe_offset($args[$arg_num - 1]); if (!isset($processors[$arg])) { return; } $processors[$arg]->react(); } }
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(); }
/** * Tests our ability to mock the cli interface * * @group wip * @covers taxonomy * */ function testTaxonomyWithExistingToAndFromExpectsTaxonomiesMigrated() { // arrange $args = $this->validTaxonomyArgs; $assoc_args = array('post_type' => 'post'); $this->posts['args'] = $args + $assoc_args; var_dump($this->posts); $mock = $this->getMockBuilder('\\CFPB\\Migrate_Command')->setMethods(array('get_specified_posts'))->getMock(); $mock->expects($this->once())->method('get_specified_posts')->will($this->returnValue($this->posts)); $new_term0 = array('slug' => 'term'); $new_term1 = array('slug' => 'another'); // mock taxonomy_exists form the WordPress API which we expect to be fired exactly twice \WP_Mock::wpFunction('taxonomy_exists', array('times' => 2, 'return' => true)); // mock wp_get_post_terms from the WordPress API which we expect to fire exactly twice $terms = \WP_Mock::wpFunction('wp_get_post_terms', array('times' => 2, 'with' => array(array($this->post0->ID, $args[0]), array($this->post1->ID, $args[0])), 'return' => $this->terms)); // mock wp_insert_term from the WordPress API which we expect to fire exactly twice $new_term = \WP_Mock::wpFunction('wp_insert_term', array('times' => 2, 'with' => array(array($this->term0->name, $args[1], array('slug' => $this->term0->slug))), 'return' => array('term_id' => 0, 'term_id' => 1))); // we expect get_term to fire twice with \WP_Mock::wpFunction('get_term', array('times' => 2, 'with' => array(array(1, $args[1])), 'return' => $this->term0)); // we expect wp_set_objec_terms to fire twice \WP_Mock::wpFunction('wp_set_object_terms', array('times' => 2, 'return' => true)); $cli = $this->cli->getMock(); $cli->expects($this->once())->method('success')->will($this->returnValue('Success')); // act $action = $mock->taxonomy($args, $assoc_args); $this->assertTrue($action == 'Success'); }
public function test_content_type() { $plugin = new Plugin(); \WP_Mock::wpFunction('register_post_type', array('times' => 3, 'arg' => array('lnh_matches'))); \WP_Mock::wpFunction('get_option', array('times' => 1, 'arg' => array('lnh_equipe_handball'), 'return' => array('equipe' => 'toulouse', 'classement' => '1', 'joueurs' => '1', 'calendrier' => '1'))); $plugin->createContentType(); }
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'); }
/** * 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.'); }
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); }
public function test_meta_box_save_rejects_invalid_before_or_after_setting() { $cpt = new CPT(); WP_Mock::wpFunction('wp_verify_nonce', array('times' => 1, 'args' => array('nonce-value', 'itelic-renewal-reminders-metabox'), 'return' => true)); WP_Mock::wpFunction('update_post_meta', array('times' => 1, 'args' => array(1, '_itelic_renewal_reminder_days', 3), 'return' => true)); WP_Mock::wpFunction('update_post_meta', array('times' => 1, 'args' => array(1, '_itelic_renewal_reminder_boa', 'before'), 'return' => true)); $cpt->do_save(1, array('itelic_reminder_nonce' => 'nonce-value', 'itelic_reminder' => array('days' => 3, 'boa' => 'garbage'))); }
/** * 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 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()); }
public function tearDown() { \WP_Mock::tearDown(); $cls = new ReflectionClass(\Dxw\Iguana\Registrar::class); $property = $cls->getProperty('singleton'); $property->setAccessible(true); $property->setValue(null); }
public function test_checkAjaxReferer() { $action = 'nonce_action'; $query_arg = '_wpnonce_name'; $myNonce = new WPnonce($action); \WP_Mock::wpFunction('check_ajax_referer', array('times' => 1, 'args' => array($myNonce->getAction(), $query_arg, true), 'return' => true)); $this->assertTrue($myNonce->checkAjaxReferer($query_arg, true)); }
/** * @covers tfrommen\ThatWasHelpful\Controllers\Action::initialize * * @return void */ public function test_initialize() { /** @var tfrommen\ThatWasHelpful\Models\Post $post */ $post = Mockery::mock('tfrommen\\ThatWasHelpful\\Models\\Post'); $testee = new Testee($post); WP_Mock::expectActionAdded('template_redirect', array($post, 'update_http')); $testee->initialize(); $this->assertHooksAdded(); }
public function test_initialize() { $model = Mockery::mock('tfrommen\\ExternalContent\\Models\\PostType'); /** @var tfrommen\ExternalContent\Models\PostType $model */ $testee = new Testee($model); WP_Mock::expectActionAdded('wp_loaded', array($model, 'register')); $testee->initialize(); $this->assertHooksAdded(); }
/** * Test activation routine. */ public function test_activate() { // Setup \WP_Mock::wpFunction('flush_rewrite_rules', array('times' => 1)); // Act activate(); // Verify $this->assertConditionsMet(); }
public function test_interval_after() { $post = new WP_Post((object) array('post_type' => Reminder\CPT::TYPE, 'ID' => 1)); WP_Mock::wpFunction('get_post_meta', array('times' => 1, 'args' => array(1, '_itelic_renewal_reminder_days', true), 'return' => 5)); WP_Mock::wpFunction('get_post_meta', array('times' => 1, 'args' => array(1, '_itelic_renewal_reminder_boa', true), 'return' => Reminder::TYPE_AFTER)); $reminder = new Reminder($post); $expects = new DateInterval('P5D'); $expects->invert = true; $this->assertEquals($expects, $reminder->get_interval()); }
/** * @covers tfrommen\ThatWasHelpful\Controllers\Update::update * @dataProvider provide_update_data * * @param bool $expected * @param string $version * @param string $old_version * * @return void */ public function test_update($expected, $version, $old_version) { $testee = new Testee($version); WP_Mock::wpFunction('get_option', array('times' => 1, 'args' => array(Mockery::type('string')), 'return' => $old_version)); if ($old_version !== $version) { WP_Mock::wpFunction('update_option', array('times' => 1, 'args' => array(Mockery::type('string'), $version))); } $this->assertSame($expected, $testee->update()); $this->assertConditionsMet(); }
function tearDown() { parent::tearDown(); WP_Mock::tearDown(); unset($this->product_factory); unset($this->key_factory); unset($this->activation_factory); unset($this->release_factory); unset($this->update_factory); }
/** * */ 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 that the actions are successfully added. */ public function test_init() { $this->dt = new \notne\Da_Tag\Da_Tag(dirname(__FILE__) . '/../'); \WP_Mock::expectActionAdded('admin_notices', array($this->dt, 'admin_notices'), 10, 1); \WP_Mock::expectActionAdded('admin_init', array($this->dt, 'admin_notices_ignore')); \WP_Mock::expectActionAdded('save_post', array($this->dt, 'save_highlighted_tag'), 10, 3); \WP_Mock::expectActionAdded('admin_enqueue_scripts', array($this->dt, 'enqueues')); \WP_Mock::expectFilterAdded('post_submitbox_misc_actions', array($this->dt, 'highlight_tag')); $this->dt->init(); }
public function test_initialize() { $model = Mockery::mock('tfrommen\\ExternalContent\\Models\\Post'); /** @var tfrommen\ExternalContent\Models\Post $model */ $testee = new Testee($model); WP_Mock::expectFilterAdded('post_type_link', array($model, 'get_external_url'), 10, 2); WP_Mock::expectFilterAdded('pre_get_shortlink', array($model, 'get_shortlink'), 10, 3); $testee->initialize(); $this->assertHooksAdded(); }
/** * 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(); }
public function test_nonce_field() { \WP_Mock::wpFunction('wp_create_nonce', array('times' => 1)); $nonce = new Nonce(); $html = $nonce->getDisplay(); $this->assertRegExp('/type=\\"hidden\\"/', $html); $this->assertRegExp('/name=\\"custom_meta_box_nonce\\"/', $html); $nonce->setValue('test'); $html_new = $nonce->getDisplay(); $this->assertEquals($html, $html_new); }
function testMissingKeyMaybeFlushRulesExpectsFlushRewriteRulesCalledOnce() { // Arrange $postTypeObj = new PostTypeObj(); \WP_Mock::wpFunction('flush_rewrite_rules', array('times' => 1, 'with' => array(true))); global $wp_rewrite; $wp_rewrite->extra_rules_top = array(); // Act $postTypeObj->maybe_flush_rewrite_rules('key'); // Assert }
public function testWpHead() { $useAtom = new \Dxw\Iguana\Extras\UseAtom(); \WP_Mock::wpFunction('get_bloginfo', ['args' => ['name'], 'return' => 'Xyz']); \WP_Mock::wpFunction('esc_attr', ['return' => function ($a) { return '_' . $a . '_'; }]); \WP_Mock::wpFunction('get_feed_link', ['args' => ['atom'], 'return' => 'xyz']); $this->expectOutputString(' <link rel="alternate" type="application/atom+xml" title="_Xyz_ Feed" href="_xyz_">' . "\n "); $useAtom->wpHead(); }
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(); }