Restore highlighting when jumping to transactions using URI anchors
[phabricator/blender.git] / src / view / layout / __tests__ / PHUIListViewTestCase.php
blobcfaf64a5748d3ba6fe586f79381d105dfd6a4cbf
1 <?php
3 final class PHUIListViewTestCase extends PhabricatorTestCase {
5 public function testAppend() {
6 $menu = $this->newABCMenu();
8 $this->assertMenuKeys(
9 array(
10 'a',
11 'b',
12 'c',
14 $menu);
17 public function testAppendAfter() {
18 $menu = $this->newABCMenu();
20 $caught = null;
21 try {
22 $menu->addMenuItemAfter('x', $this->newLink('test1'));
23 } catch (Exception $ex) {
24 $caught = $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(
34 array(
35 'a',
36 'test4',
37 'test2',
38 'b',
39 'c',
40 'test3',
41 'test5',
43 $menu);
46 public function testAppendBefore() {
47 $menu = $this->newABCMenu();
49 $caught = null;
50 try {
51 $menu->addMenuItemBefore('x', $this->newLink('test1'));
52 } catch (Exception $ex) {
53 $caught = $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(
63 array(
64 'test5',
65 'test3',
66 'test4',
67 'a',
68 'test2',
69 'b',
70 'c',
72 $menu);
75 public function testAppendLabel() {
76 $menu = new PHUIListView();
77 $menu->addMenuItem($this->newLabel('fruit'));
78 $menu->addMenuItem($this->newLabel('animals'));
80 $caught = null;
81 try {
82 $menu->addMenuItemToLabel('x', $this->newLink('test1'));
83 } catch (Exception $ex) {
84 $caught = $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(
97 array(
98 'fruit',
99 'apple',
100 'banana',
101 'cherry',
102 'animals',
103 'dog',
104 'cat',
106 $menu);
109 private function newLink($key) {
110 return id(new PHUIListItemView())
111 ->setKey($key)
112 ->setHref('#')
113 ->setName(pht('Link'));
116 private function newLabel($key) {
117 return id(new PHUIListItemView())
118 ->setType(PHUIListItemView::TYPE_LABEL)
119 ->setKey($key)
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'));
130 return $menu;
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);