Code Duplication    Length = 6-12 lines in 5 locations

projects/plugins/jetpack/tests/php/modules/contact-form/test-class.grunion-contact-form.php 5 locations

@@ 627-635 (lines=9) @@
624
	 *
625
	 * @author tonykova
626
	 */
627
	public function test_parse_contact_field_keeps_string_unchanged_when_no_escaping_necesssary() {
628
		add_shortcode( 'contact-field', array( 'Grunion_Contact_Form', 'parse_contact_field' ) );
629
630
		// @phpcs:ignore Squiz.Strings.DoubleQuoteUsage.NotRequired
631
		$shortcode = "[contact-field label=\"Name\" type=\"name\" required=\"1\"/][contact-field label=\"Email\" type=\"email\" required=\"1\"/][contact-field label=\"asdasd\" type=\"text\"/][contact-field id=\"1\" required derp herp asd lkj]adsasd[/contact-field]";
632
		$html      = do_shortcode( $shortcode );
633
634
		$this->assertEquals( $shortcode, $html );
635
	}
636
637
	/**
638
	 * Tests that the default label is added when no label is present.
@@ 640-646 (lines=7) @@
637
	/**
638
	 * Tests that the default label is added when no label is present.
639
	 */
640
	public function test_make_sure_that_we_add_default_label_when_non_is_present() {
641
		add_shortcode( 'contact-field', array( 'Grunion_Contact_Form', 'parse_contact_field' ) );
642
		$shortcode = "[contact-field type='name' required='1' /]";
643
		$html      = do_shortcode( $shortcode );
644
		// @phpcs:ignore Squiz.Strings.DoubleQuoteUsage.NotRequired
645
		$this->assertEquals( "[contact-field type=\"name\" required=\"1\" label=\"Name\"/]", $html );
646
	}
647
648
	/**
649
	 * Tests the empty options are removed from form fields.
@@ 651-657 (lines=7) @@
648
	/**
649
	 * Tests the empty options are removed from form fields.
650
	 */
651
	public function test_make_sure_that_we_remove_empty_options_from_form_field() {
652
		add_shortcode( 'contact-field', array( 'Grunion_Contact_Form', 'parse_contact_field' ) );
653
		$shortcode = "[contact-field type='select' required='1' options='fun,,run' label='fun times' values='go,,have some fun'/]";
654
		$html      = do_shortcode( $shortcode );
655
		// @phpcs:ignore Squiz.Strings.DoubleQuoteUsage.NotRequired
656
		$this->assertEquals( "[contact-field type=\"select\" required=\"1\" options=\"fun,run\" label=\"fun times\" values=\"go,have some fun\"/]", $html );
657
	}
658
659
	/**
660
	 * Tests shortcode with commas and brackets.
@@ 664-669 (lines=6) @@
661
	 *
662
	 * @covers Grunion_Contact_Form_Field
663
	 */
664
	public function test_array_values_with_commas_and_brackets() {
665
		add_shortcode( 'contact-field', array( 'Grunion_Contact_Form', 'parse_contact_field' ) );
666
		$shortcode = "[contact-field type='radio' options='\"foo\",bar, baz,[b\rackets]' label='fun ][ times'/]";
667
		$html      = do_shortcode( $shortcode );
668
		$this->assertEquals( '[contact-field type="radio" options=""foo",bar, baz,[b\rackets]" label="fun ][ times"/]', $html );
669
	}
670
671
	/**
672
	 * Tests Gutenblock input with commas and brackets.
@@ 1115-1126 (lines=12) @@
1112
	 *
1113
	 * @author tonykova
1114
	 */
1115
	public function test_parse_contact_field_escapes_things_inside_a_value_and_attribute_and_the_content() {
1116
		add_shortcode( 'contact-field', array( 'Grunion_Contact_Form', 'parse_contact_field' ) );
1117
1118
		$shortcode = "[contact-field label='Name' type='name' required='1'/][contact-field label='Email' type=''email'' req'uired='1'/][contact-field label='asdasd' type='text'/][contact-field id='1' required 'derp' herp asd lkj]adsasd[/contact-field]";
1119
		$html      = do_shortcode( $shortcode );
1120
1121
		/*
1122
		 * The expected string has some quotes escaped, since we want to make
1123
		 * sure we don't output anything harmful
1124
		 */
1125
		$this->assertEquals( '[contact-field label="Name" type="name" required="1"/][contact-field label="Email" type=''email'' req'uired='1'/][contact-field label="asdasd" type="text"/][contact-field id="1" required derp herp asd lkj]adsasd[/contact-field]', $html );
1126
	}
1127
1128
	/**
1129
	 * Test get_export_data_for_posts with fully vaid data input.