@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PHUIInvisibleCharacterTestCase extends PhabricatorTestCase {
4
5 public function testEmptyString() {
6 $view = new PHUIInvisibleCharacterView('');
7 $res = $view->render();
8 $this->assertEqual($res, array());
9 }
10
11 public function testEmptyPlainText() {
12 $view = id(new PHUIInvisibleCharacterView(''))
13 ->setPlainText(true);
14 $res = $view->render();
15 $this->assertEqual($res, '');
16 }
17
18 public function testWithNamedChars() {
19 $test_input = "\x00\n\t ";
20 $view = id(new PHUIInvisibleCharacterView($test_input))
21 ->setPlainText(true);
22 $res = $view->render();
23 $this->assertEqual($res, '<NULL><NEWLINE><TAB><SPACE>');
24 }
25
26 public function testWithHexChars() {
27 $test_input = "abc\x01";
28 $view = id(new PHUIInvisibleCharacterView($test_input))
29 ->setPlainText(true);
30 $res = $view->render();
31 $this->assertEqual($res, 'abc<0x01>');
32 }
33
34 public function testWithNamedAsHex() {
35 $test_input = "\x00\x0a\x09\x20";
36 $view = id(new PHUIInvisibleCharacterView($test_input))
37 ->setPlainText(true);
38 $res = $view->render();
39 $this->assertEqual($res, '<NULL><NEWLINE><TAB><SPACE>');
40 }
41
42 public function testHtmlDecoration() {
43 $test_input = "a\x00\n\t ";
44 $view = new PHUIInvisibleCharacterView($test_input);
45 $res = $view->render();
46 $this->assertFalse($res[0] instanceof PhutilSafeHTML);
47 $this->assertTrue($res[1] instanceof PhutilSafeHTML);
48 $this->assertTrue($res[2] instanceof PhutilSafeHTML);
49 $this->assertTrue($res[3] instanceof PhutilSafeHTML);
50 $this->assertTrue($res[4] instanceof PhutilSafeHTML);
51 }
52}