[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/layout/__tests__/ -> PHUIListViewTestCase.php (source)

   1  <?php
   2  
   3  final class PHUIListViewTestCase extends PhabricatorTestCase {
   4  
   5    public function testAppend() {
   6      $menu = $this->newABCMenu();
   7  
   8      $this->assertMenuKeys(
   9        array(
  10          'a',
  11          'b',
  12          'c',
  13        ),
  14        $menu);
  15    }
  16  
  17    public function testAppendAfter() {
  18      $menu = $this->newABCMenu();
  19  
  20      $caught = null;
  21      try {
  22        $menu->addMenuItemAfter('x', $this->newLink('test1'));
  23      } catch (Exception $ex) {
  24        $caught = $ex;
  25      }
  26      $this->assertTrue($caught instanceof Exception);
  27  
  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'));
  32  
  33      $this->assertMenuKeys(
  34        array(
  35          'a',
  36          'test4',
  37          'test2',
  38          'b',
  39          'c',
  40          'test3',
  41          'test5',
  42        ),
  43        $menu);
  44    }
  45  
  46    public function testAppendBefore() {
  47      $menu = $this->newABCMenu();
  48  
  49      $caught = null;
  50      try {
  51        $menu->addMenuItemBefore('x', $this->newLink('test1'));
  52      } catch (Exception $ex) {
  53        $caught = $ex;
  54      }
  55      $this->assertTrue($caught instanceof Exception);
  56  
  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'));
  61  
  62      $this->assertMenuKeys(
  63        array(
  64          'test5',
  65          'test3',
  66          'test4',
  67          'a',
  68          'test2',
  69          'b',
  70          'c',
  71        ),
  72        $menu);
  73    }
  74  
  75    public function testAppendLabel() {
  76      $menu = new PHUIListView();
  77      $menu->addMenuItem($this->newLabel('fruit'));
  78      $menu->addMenuItem($this->newLabel('animals'));
  79  
  80      $caught = null;
  81      try {
  82        $menu->addMenuItemToLabel('x', $this->newLink('test1'));
  83      } catch (Exception $ex) {
  84        $caught = $ex;
  85      }
  86      $this->assertTrue($caught instanceof Exception);
  87  
  88      $menu->addMenuItemToLabel('fruit', $this->newLink('apple'));
  89      $menu->addMenuItemToLabel('fruit', $this->newLink('banana'));
  90  
  91      $menu->addMenuItemToLabel('animals', $this->newLink('dog'));
  92      $menu->addMenuItemToLabel('animals', $this->newLink('cat'));
  93  
  94      $menu->addMenuItemToLabel('fruit', $this->newLink('cherry'));
  95  
  96      $this->assertMenuKeys(
  97        array(
  98          'fruit',
  99            'apple',
 100            'banana',
 101            'cherry',
 102          'animals',
 103            'dog',
 104            'cat',
 105        ),
 106        $menu);
 107    }
 108  
 109    private function newLink($key) {
 110      return id(new PHUIListItemView())
 111        ->setKey($key)
 112        ->setHref('#')
 113        ->setName('Link');
 114    }
 115  
 116    private function newLabel($key) {
 117      return id(new PHUIListItemView())
 118        ->setType(PHUIListItemView::TYPE_LABEL)
 119        ->setKey($key)
 120        ->setName('Label');
 121    }
 122  
 123    private function newABCMenu() {
 124      $menu = new PHUIListView();
 125  
 126      $menu->addMenuItem($this->newLink('a'));
 127      $menu->addMenuItem($this->newLink('b'));
 128      $menu->addMenuItem($this->newLink('c'));
 129  
 130      return $menu;
 131    }
 132  
 133    private function assertMenuKeys(array $expect, PHUIListView $menu) {
 134      $items = $menu->getItems();
 135      $keys = mpull($items, 'getKey');
 136      $keys = array_values($keys);
 137  
 138      $this->assertEqual($expect, $keys);
 139    }
 140  
 141  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1