Changeset View
Changeset View
Standalone View
Standalone View
src/view/phui/__tests__/PHUIInvisibleCharacterTestCase.php
- This file was added.
<?php | |||||
final class PHUIInvisibleCharacterTestCase extends PhabricatorTestCase { | |||||
public function testEmptyString() { | |||||
$view = new PHUIInvisibleCharacterView(''); | |||||
$res = $view->render(); | |||||
$this->assertEqual($res, array()); | |||||
} | |||||
public function testEmptyPlainText() { | |||||
$view = new PHUIInvisibleCharacterView('', true); | |||||
$res = $view->render(); | |||||
$this->assertEqual($res, ''); | |||||
} | |||||
public function testHtmlWithNamedChars() { | |||||
$test_input = "\x00\n\t "; | |||||
$view = new PHUIInvisibleCharacterView($test_input); | |||||
$res = $view->render(); | |||||
$this->assertEqual($res[0]->getHtmlContent(), $this->getNullHtml()); | |||||
$this->assertEqual($res[1]->getHtmlContent(), $this->getNewlineHtml()); | |||||
$this->assertEqual($res[2]->getHtmlContent(), $this->getTabHtml()); | |||||
$this->assertEqual($res[3]->getHtmlContent(), $this->getSpaceHtml()); | |||||
} | |||||
public function testPlainWithNamedChars() { | |||||
$test_input = "\x00\n\t "; | |||||
$view = new PHUIInvisibleCharacterView($test_input, true); | |||||
$res = $view->render(); | |||||
$this->assertEqual($res, '<NULL><NEWLINE><TAB><SPACE>'); | |||||
} | |||||
public function testHtmlWithHexChars() { | |||||
$test_input = "abc\x01"; | |||||
$view = new PHUIInvisibleCharacterView($test_input); | |||||
$res = $view->render(); | |||||
$this->assertEqual($res[3]->getHtmlContent(), $this->getHexHtml()); | |||||
} | |||||
public function testPlainWithHexChars() { | |||||
$test_input = "abc\x01"; | |||||
$view = new PHUIInvisibleCharacterView($test_input, true); | |||||
$res = $view->render(); | |||||
$this->assertEqual($res, 'abc<0x01>'); | |||||
} | |||||
public function testHTMLWithNamedAsHex() { | |||||
$test_input = "\x00\x0a\x09\x20"; | |||||
$view = new PHUIInvisibleCharacterView($test_input); | |||||
$res = $view->render(); | |||||
$this->assertEqual($res[0]->getHtmlContent(), $this->getNullHtml()); | |||||
$this->assertEqual($res[1]->getHtmlContent(), $this->getNewlineHtml()); | |||||
$this->assertEqual($res[2]->getHtmlContent(), $this->getTabHtml()); | |||||
$this->assertEqual($res[3]->getHtmlContent(), $this->getSpaceHtml()); | |||||
} | |||||
public function testPlainWithNamedAsHex() { | |||||
$test_input = "\x00\x0a\x09\x20"; | |||||
$view = new PHUIInvisibleCharacterView($test_input, true); | |||||
$res = $view->render(); | |||||
$this->assertEqual($res, '<NULL><NEWLINE><TAB><SPACE>'); | |||||
} | |||||
private function getNullHtml() { | |||||
return phutil_tag( | |||||
'span', | |||||
array('class' => 'invisible-special'), | |||||
'<NULL>') | |||||
->getHtmlContent(); | |||||
} | |||||
private function getTabHtml() { | |||||
return phutil_tag( | |||||
'span', | |||||
array('class' => 'invisible-special'), | |||||
'<TAB>') | |||||
->getHtmlContent(); | |||||
} | |||||
private function getNewlineHtml() { | |||||
return phutil_tag( | |||||
'span', | |||||
array('class' => 'invisible-special'), | |||||
'<NEWLINE>') | |||||
->getHtmlContent(); | |||||
} | |||||
private function getSpaceHtml() { | |||||
return phutil_tag( | |||||
'span', | |||||
array('class' => 'invisible-special'), | |||||
'<SPACE>') | |||||
->getHtmlContent(); | |||||
} | |||||
private function getHexHtml() { | |||||
return phutil_tag( | |||||
'span', | |||||
array('class' => 'invisible-special'), | |||||
'<0x01>') | |||||
->getHtmlContent(); | |||||
} | |||||
} |