/** * 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 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'; 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()); }
/** * 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')); }