world

"); $this->assert_equal("hello <p>world</p>", $safe_string); } public function toString_for_safe_string_test() { $safe_string = SafeString::of_safe_html("hello

world

"); $this->assert_equal("hello

world

", $safe_string); } public function for_html_test() { $safe_string = new SafeString("hello

world

"); $this->assert_equal("hello <p>world</p>", $safe_string->for_html()); } public function safestring_of_safestring_test() { $safe_string = new SafeString("hello

world

"); $safe_string_2 = new SafeString($safe_string); $this->assert_true($safe_string_2 instanceof SafeString); $raw_string = $safe_string_2->unescaped(); $this->assert_false(is_object($raw_string)); $this->assert_equal("hello

world

", $raw_string); $this->assert_equal("hello <p>world</p>", $safe_string_2); } public function for_js_test() { $safe_string = new SafeString('"Foo\'s bar"'); $js_string = $safe_string->for_js(); $this->assert_equal('"\\"Foo<\\/em>\'s bar\\""', $js_string); } public function for_html_attr_test() { $safe_string = new SafeString('"Foo\'s bar"'); $attr_string = $safe_string->for_html_attr(); $this->assert_equal('"<em>Foo</em>'s bar"', $attr_string); } public function for_html_attr_with_safe_html_test() { $safe_string = SafeString::of_safe_html('"Foo\'s bar"'); $attr_string = $safe_string->for_html_attr(); $this->assert_equal('"Foo's bar"', $attr_string); } public function string_safestring_equality_test() { $safe_string = new SafeString("hello

world

"); $this->assert_equal("hello

world

", $safe_string->unescaped()); $escaped_string = "hello <p>world</p>"; $this->assert_equal($escaped_string, $safe_string); $this->assert_true($escaped_string == $safe_string); $this->assert_false($escaped_string === $safe_string); $this->assert_false("meow" == $safe_string); } public function of_test() { $safe_string = SafeString::of("hello

world

"); $this->assert_equal("hello

world

", $safe_string->unescaped()); } public function of_safe_html_test() { $safe_string = SafeString::of_safe_html("hello

world

"); $this->assert_equal("hello

world

", $safe_string->for_html()); } public function purify_test() { $safe_string = SafeString::purify("hello

world

"); $expected = method_exists("purifier", "purify") ? "hello

world

" : "hello <p >world</p>"; $this->assert_equal($expected, $safe_string); } public function purify_twice_test() { $safe_string = SafeString::purify("hello

world

"); $safe_string_2 = SafeString::purify($safe_string); $expected = method_exists("purifier", "purify") ? "hello

world

" : "hello <p >world</p>"; $this->assert_equal($expected, $safe_string_2); } public function purify_safe_html_test() { $safe_string = SafeString::of_safe_html("hello

world

"); $actual = SafeString::purify($safe_string); $this->assert_equal("hello

world

", $actual); } public function of_fluid_api_test() { $escaped_string = SafeString::of("Foo's bar")->for_js(); $this->assert_equal('"Foo\'s bar"', $escaped_string); } public function safestring_of_safestring_preserves_safe_status_test() { $safe_string = SafeString::of_safe_html("hello's

world

"); $safe_string_2 = new SafeString($safe_string); $this->assert_equal("hello's

world

", $safe_string_2); $this->assert_equal('"hello\'s

world<\\/p>"', $safe_string_2->for_js()); } public function safestring_of_safestring_preserves_html_safe_status_test() { $safe_string = SafeString::of_safe_html("hello's

world

"); $safe_string_2 = new SafeString($safe_string); $this->assert_equal("hello's

world

", $safe_string_2); $this->assert_equal('"hello\'s

world<\\/p>"', $safe_string_2->for_js()); } public function safestring_of_safestring_safe_status_override_test() { $safe_string = new SafeString("hello

world

"); $safe_string_2 = SafeString::of_safe_html($safe_string); $this->assert_equal("hello

world

", $safe_string_2); } }