3 final class PHUIListViewTestCase
extends PhabricatorTestCase
{
5 public function testAppend() {
6 $menu = $this->newABCMenu();
17 public function testAppendAfter() {
18 $menu = $this->newABCMenu();
22 $menu->addMenuItemAfter('x', $this->newLink('test1'));
23 } catch (Exception
$ex) {
26 $this->assertTrue($caught instanceof Exception
);
28 $menu->addMenuItemAfter('a', $this->newLink('test2'));
29 $menu->addMenuItemAfter(null, $this->newLink('test3'));
30 $menu->addMenuItemAfter('a', $this->newLink('test4'));
31 $menu->addMenuItemAfter('test3', $this->newLink('test5'));
33 $this->assertMenuKeys(
46 public function testAppendBefore() {
47 $menu = $this->newABCMenu();
51 $menu->addMenuItemBefore('x', $this->newLink('test1'));
52 } catch (Exception
$ex) {
55 $this->assertTrue($caught instanceof Exception
);
57 $menu->addMenuItemBefore('b', $this->newLink('test2'));
58 $menu->addMenuItemBefore(null, $this->newLink('test3'));
59 $menu->addMenuItemBefore('a', $this->newLink('test4'));
60 $menu->addMenuItemBefore('test3', $this->newLink('test5'));
62 $this->assertMenuKeys(
75 public function testAppendLabel() {
76 $menu = new PHUIListView();
77 $menu->addMenuItem($this->newLabel('fruit'));
78 $menu->addMenuItem($this->newLabel('animals'));
82 $menu->addMenuItemToLabel('x', $this->newLink('test1'));
83 } catch (Exception
$ex) {
86 $this->assertTrue($caught instanceof Exception
);
88 $menu->addMenuItemToLabel('fruit', $this->newLink('apple'));
89 $menu->addMenuItemToLabel('fruit', $this->newLink('banana'));
91 $menu->addMenuItemToLabel('animals', $this->newLink('dog'));
92 $menu->addMenuItemToLabel('animals', $this->newLink('cat'));
94 $menu->addMenuItemToLabel('fruit', $this->newLink('cherry'));
96 $this->assertMenuKeys(
109 private function newLink($key) {
110 return id(new PHUIListItemView())
113 ->setName(pht('Link'));
116 private function newLabel($key) {
117 return id(new PHUIListItemView())
118 ->setType(PHUIListItemView
::TYPE_LABEL
)
120 ->setName(pht('Label'));
123 private function newABCMenu() {
124 $menu = new PHUIListView();
126 $menu->addMenuItem($this->newLink('a'));
127 $menu->addMenuItem($this->newLink('b'));
128 $menu->addMenuItem($this->newLink('c'));
133 private function assertMenuKeys(array $expect, PHUIListView
$menu) {
134 $items = $menu->getItems();
135 $keys = mpull($items, 'getKey');
136 $keys = array_values($keys);
138 $this->assertEqual($expect, $keys);