/** * Test for the validate() method. * * @dataProvider provide_validate_data * * @param bool $expected * @param array $properties * @param string $request_method * * @return void */ public function test_validate($expected, array $properties, $request_method) { $_SERVER['REQUEST_METHOD'] = $request_method; $testee = new Testee($properties); Monkey\Functions::when('wp_verify_nonce')->justReturn(true); $this->assertSame($expected, $testee->validate()); }
/** * Test for the validate() method. * * @return void */ public function test_validate() { $action = 'action'; $nonce = 'nonce'; $testee = new Testee(compact('action', 'nonce')); Monkey\Functions::expect('wp_verify_nonce')->with($nonce, $action)->andReturn(true); $this->assertTrue($testee->validate()); }
/** * Test for the create() method. * * @dataProvider provide_create_data * * @param string $expected_action * @param string $expected_name * @param string $action * @param string $name * * @return void */ public function test_create($expected_action, $expected_name, $action, $name) { $testee = new Testee(); Monkey\Functions::when('sanitize_title_with_dashes')->returnArg(); $context = $testee->create($action, $name); $this->assertSame($expected_action, $context->get_action()); $this->assertSame($expected_name, $context->get_name()); }
/** * Test for the create() method. * * @return void */ public function test_create() { $testee = new Testee(); $action = 'action'; /** @var Context $context */ $context = Mockery::mock('Inpsyde\\Nonces\\Context')->shouldReceive('get_action')->andReturn($action)->getMock(); Monkey\Functions::expect('wp_create_nonce')->with($action); $this->assertInstanceOf('Inpsyde\\Nonces\\Nonce', $testee->create($context)); }
/** * Test for the create() method. * * @return void */ public function test_create() { $testee = new Testee(); $action = 'action'; Monkey\Functions::when('sanitize_title_with_dashes'); $context = new Context($action); $nonce_value = 'nonce'; Monkey\Functions::expect('wp_create_nonce')->with($action)->andReturn($nonce_value); $nonce = $testee->create($context); $this->assertSame($nonce_value, $nonce->get()); }
function test_check_admin_referral() { //Setup Functions::expect('wp_create_nonce')->once()->with('doing_some_admin_job')->andReturn('abged45fg'); Functions::expect('check_admin_referer')->once()->with('doing_some_admin_job', '_wpnonce')->andReturn(1); //Act $nonce = new Nonce_Wrapper('doing_some_admin_job'); $nonce_val = $nonce->create_nonce(); $_REQUEST['_wpnonce'] = $nonce_val; //Verify $this->assertEquals($nonce->check_admin_referral(), 1); }
/** * Test for the render() method. * * @return void */ public function test_render() { $testee = new Testee(); $action = 'action'; $name = 'name'; /** @var Context $context */ $context = Mockery::mock('Inpsyde\\Nonces\\Context')->shouldReceive('get_action')->andReturn($action)->shouldReceive('get_name')->andReturn($name)->getMock(); $nonce_field = 'nonce_field'; Monkey\Functions::expect('wp_nonce_field')->with($action, $name, false, false)->andReturn($nonce_field); $this->expectOutputString($nonce_field); $testee->render($context); }
/** * Test for the render() method. * * @return void */ public function test_render() { $testee = new Testee(); $action = 'action'; $name = 'name'; Monkey\Functions::when('sanitize_title_with_dashes')->returnArg(); $context = new Context($action, $name); $nonce_field = 'nonce_field'; Monkey\Functions::expect('wp_nonce_field')->with($action, $name, false, false)->andReturn($nonce_field); $this->expectOutputString($nonce_field); $testee->render($context); }
/** * Test for the render() method. * * @return void */ public function test_render() { $testee = new Testee(); $action = 'action'; $name = 'name'; Monkey\Functions::when('sanitize_title_with_dashes')->returnArg(); $context = new Context($action, $name); $nonce = 'nonce'; Monkey\Functions::expect('wp_create_nonce')->with($action)->andReturn($nonce); Monkey\Functions::when('esc_attr')->returnArg(); $this->expectOutputString("data-{$name}=\"{$nonce}\""); $testee->render($context); }
/** * Test for the render() method. * * @return void */ public function test_render() { $testee = new Testee(); $action = 'action'; $nonce = 'nonce'; Monkey\Functions::expect('wp_create_nonce')->with($action)->andReturn($nonce); $name = 'name'; /** @var Context $context */ $context = Mockery::mock('Inpsyde\\Nonces\\Context')->shouldReceive('get_action')->andReturn($action)->shouldReceive('get_name')->andReturn($name)->getMock(); Monkey\Functions::when('esc_attr')->returnArg(); $this->expectOutputString("data-{$name}=\"{$nonce}\""); $testee->render($context); }
/** * Test for the get_name() method. * * @dataProvider provide_get_name_data * * @param string $expected * @param string $action * @param string $name * * @return void */ public function test_get_name($expected, $action, $name) { Monkey\Functions::when('sanitize_title_with_dashes')->returnArg(); $testee = new Testee($action, $name); $this->assertSame($expected, $testee->get_name()); }
/** * Test for the create() method. * * @return void */ public function test_create() { $testee = new Testee(); Monkey\Functions::when('sanitize_title_with_dashes'); $this->assertInstanceOf('Inpsyde\\Nonces\\Context', $testee->create('action')); }
/** * Clean up Functions and Hooks statics: is always needed when using this class. */ public static function tearDown() { Patchwork\undoAll(); Mockery::close(); Functions::__flush(); }