/** * @group link_html * @covers ::gravityview_get_link() * @covers GVCommon::get_link_html */ function test_get_link_html() { $this->assertEquals('<a href="#">Basic</a>', GVCommon::get_link_html('#', 'Basic')); $this->assertEquals('<a title="New Title" href="#">Basic</a>', GVCommon::get_link_html('#', 'Basic', array('title' => 'New Title'))); $this->assertEquals('<a title="New Title" href="#">Basic</a>', GVCommon::get_link_html('#', 'Basic', array('title' => 'New Title'))); $this->assertEquals('<a onclick="alert("Javascript!");" href="#">Basic</a>', GVCommon::get_link_html('#', 'Basic', array('onclick' => 'alert("Javascript!");'))); // Make sure running esc_url_raw $href = '//?dangerous=alert("example");"%20;'; $this->assertEquals('<a href="' . esc_url_raw($href) . '">Basic</a>', GVCommon::get_link_html($href, 'Basic')); // Test gravityview/get_link/allowed_atts filter add_filter('gravityview/get_link/allowed_atts', array($this, '_filter_test_get_link_html')); $this->assertEquals('<a href="#">Basic</a>', GVCommon::get_link_html('#', 'Basic', array('onclick' => 'alert("Javascript!");'))); remove_filter('', array($this, '_filter_test_get_link_html')); }
/** * Generate an HTML anchor tag with a list of supported attributes * * @see GVCommon::get_link_html() * * @since 1.6 * * @param string $href URL of the link. * @param string $anchor_text The text or HTML inside the anchor. This is not sanitized in the function. * @param array $atts Attributes to be added to the anchor tag * * @return string HTML output of anchor link. If empty $href, returns NULL */ function gravityview_get_link($href = '', $anchor_text = '', $atts = array()) { return GVCommon::get_link_html($href, $anchor_text, $atts); }