Changeset View
Changeset View
Standalone View
Standalone View
src/view/phui/__tests__/PHUIInvisibleCharacterTestCase.php
| <?php | <?php | ||||
| final class PHUIInvisibleCharacterTestCase extends PhabricatorTestCase { | final class PHUIInvisibleCharacterTestCase extends PhabricatorTestCase { | ||||
| public function testEmptyString() { | public function testEmptyString() { | ||||
| $view = new PHUIInvisibleCharacterView(''); | $view = new PHUIInvisibleCharacterView(''); | ||||
| $res = $view->render(); | $res = $view->render(); | ||||
| $this->assertEqual($res, array()); | $this->assertEqual($res, array()); | ||||
| } | } | ||||
| public function testEmptyPlainText() { | public function testEmptyPlainText() { | ||||
| $view = (new PHUIInvisibleCharacterView('')) | $view = id(new PHUIInvisibleCharacterView('')) | ||||
| ->setPlainText(true); | ->setPlainText(true); | ||||
| $res = $view->render(); | $res = $view->render(); | ||||
| $this->assertEqual($res, ''); | $this->assertEqual($res, ''); | ||||
| } | } | ||||
| public function testWithNamedChars() { | public function testWithNamedChars() { | ||||
| $test_input = "\x00\n\t "; | $test_input = "\x00\n\t "; | ||||
| $view = (new PHUIInvisibleCharacterView($test_input)) | $view = id(new PHUIInvisibleCharacterView($test_input)) | ||||
| ->setPlainText(true); | ->setPlainText(true); | ||||
| $res = $view->render(); | $res = $view->render(); | ||||
| $this->assertEqual($res, '<NULL><NEWLINE><TAB><SPACE>'); | $this->assertEqual($res, '<NULL><NEWLINE><TAB><SPACE>'); | ||||
| } | } | ||||
| public function testWithHexChars() { | public function testWithHexChars() { | ||||
| $test_input = "abc\x01"; | $test_input = "abc\x01"; | ||||
| $view = (new PHUIInvisibleCharacterView($test_input)) | $view = id(new PHUIInvisibleCharacterView($test_input)) | ||||
| ->setPlainText(true); | ->setPlainText(true); | ||||
| $res = $view->render(); | $res = $view->render(); | ||||
| $this->assertEqual($res, 'abc<0x01>'); | $this->assertEqual($res, 'abc<0x01>'); | ||||
| } | } | ||||
| public function testWithNamedAsHex() { | public function testWithNamedAsHex() { | ||||
| $test_input = "\x00\x0a\x09\x20"; | $test_input = "\x00\x0a\x09\x20"; | ||||
| $view = (new PHUIInvisibleCharacterView($test_input)) | $view = id(new PHUIInvisibleCharacterView($test_input)) | ||||
| ->setPlainText(true); | ->setPlainText(true); | ||||
| $res = $view->render(); | $res = $view->render(); | ||||
| $this->assertEqual($res, '<NULL><NEWLINE><TAB><SPACE>'); | $this->assertEqual($res, '<NULL><NEWLINE><TAB><SPACE>'); | ||||
| } | } | ||||
| public function testHtmlDecoration() { | public function testHtmlDecoration() { | ||||
| $test_input = "a\x00\n\t "; | $test_input = "a\x00\n\t "; | ||||
| $view = new PHUIInvisibleCharacterView($test_input); | $view = new PHUIInvisibleCharacterView($test_input); | ||||
| $res = $view->render(); | $res = $view->render(); | ||||
| $this->assertFalse($res[0] instanceof PhutilSafeHTML); | $this->assertFalse($res[0] instanceof PhutilSafeHTML); | ||||
| $this->assertTrue($res[1] instanceof PhutilSafeHTML); | $this->assertTrue($res[1] instanceof PhutilSafeHTML); | ||||
| $this->assertTrue($res[2] instanceof PhutilSafeHTML); | $this->assertTrue($res[2] instanceof PhutilSafeHTML); | ||||
| $this->assertTrue($res[3] instanceof PhutilSafeHTML); | $this->assertTrue($res[3] instanceof PhutilSafeHTML); | ||||
| $this->assertTrue($res[4] instanceof PhutilSafeHTML); | $this->assertTrue($res[4] instanceof PhutilSafeHTML); | ||||
| } | } | ||||
| } | } | ||||