Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F106522008
PhabricatorMenuViewTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Mar 26, 18:42
Size
3 KB
Mime Type
text/x-php
Expires
Fri, Mar 28, 18:42 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25207668
Attached To
rPH Phabricator
PhabricatorMenuViewTestCase.php
View Options
<?php
final
class
PhabricatorMenuViewTestCase
extends
PhabricatorTestCase
{
public
function
testAppend
()
{
$menu
=
$this
->
newABCMenu
();
$this
->
assertMenuKeys
(
array
(
'a'
,
'b'
,
'c'
,
),
$menu
);
}
public
function
testAppendAfter
()
{
$menu
=
$this
->
newABCMenu
();
$caught
=
null
;
try
{
$menu
->
addMenuItemAfter
(
'x'
,
$this
->
newLink
(
'test1'
));
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
$this
->
assertEqual
(
true
,
$caught
instanceof
Exception
);
$menu
->
addMenuItemAfter
(
'a'
,
$this
->
newLink
(
'test2'
));
$menu
->
addMenuItemAfter
(
null
,
$this
->
newLink
(
'test3'
));
$menu
->
addMenuItemAfter
(
'a'
,
$this
->
newLink
(
'test4'
));
$menu
->
addMenuItemAfter
(
'test3'
,
$this
->
newLink
(
'test5'
));
$this
->
assertMenuKeys
(
array
(
'a'
,
'test4'
,
'test2'
,
'b'
,
'c'
,
'test3'
,
'test5'
,
),
$menu
);
}
public
function
testAppendBefore
()
{
$menu
=
$this
->
newABCMenu
();
$caught
=
null
;
try
{
$menu
->
addMenuItemBefore
(
'x'
,
$this
->
newLink
(
'test1'
));
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
$this
->
assertEqual
(
true
,
$caught
instanceof
Exception
);
$menu
->
addMenuItemBefore
(
'b'
,
$this
->
newLink
(
'test2'
));
$menu
->
addMenuItemBefore
(
null
,
$this
->
newLink
(
'test3'
));
$menu
->
addMenuItemBefore
(
'a'
,
$this
->
newLink
(
'test4'
));
$menu
->
addMenuItemBefore
(
'test3'
,
$this
->
newLink
(
'test5'
));
$this
->
assertMenuKeys
(
array
(
'test5'
,
'test3'
,
'test4'
,
'a'
,
'test2'
,
'b'
,
'c'
,
),
$menu
);
}
public
function
testAppendLabel
()
{
$menu
=
new
PhabricatorMenuView
();
$menu
->
addMenuItem
(
$this
->
newLabel
(
'fruit'
));
$menu
->
addMenuItem
(
$this
->
newLabel
(
'animals'
));
$caught
=
null
;
try
{
$menu
->
addMenuItemToLabel
(
'x'
,
$this
->
newLink
(
'test1'
));
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
$this
->
assertEqual
(
true
,
$caught
instanceof
Exception
);
$menu
->
addMenuItemToLabel
(
'fruit'
,
$this
->
newLink
(
'apple'
));
$menu
->
addMenuItemToLabel
(
'fruit'
,
$this
->
newLink
(
'banana'
));
$menu
->
addMenuItemToLabel
(
'animals'
,
$this
->
newLink
(
'dog'
));
$menu
->
addMenuItemToLabel
(
'animals'
,
$this
->
newLink
(
'cat'
));
$menu
->
addMenuItemToLabel
(
'fruit'
,
$this
->
newLink
(
'cherry'
));
$this
->
assertMenuKeys
(
array
(
'fruit'
,
'apple'
,
'banana'
,
'cherry'
,
'animals'
,
'dog'
,
'cat'
,
),
$menu
);
}
private
function
newLink
(
$key
)
{
return
id
(
new
PhabricatorMenuItemView
())
->
setKey
(
$key
)
->
setHref
(
'#'
)
->
setName
(
'Link'
);
}
private
function
newLabel
(
$key
)
{
return
id
(
new
PhabricatorMenuItemView
())
->
setType
(
PhabricatorMenuItemView
::
TYPE_LABEL
)
->
setKey
(
$key
)
->
setName
(
'Label'
);
}
private
function
newABCMenu
()
{
$menu
=
new
PhabricatorMenuView
();
$menu
->
addMenuItem
(
$this
->
newLink
(
'a'
));
$menu
->
addMenuItem
(
$this
->
newLink
(
'b'
));
$menu
->
addMenuItem
(
$this
->
newLink
(
'c'
));
return
$menu
;
}
private
function
assertMenuKeys
(
array
$expect
,
PhabricatorMenuView
$menu
)
{
$items
=
$menu
->
getItems
();
$keys
=
mpull
(
$items
,
'getKey'
);
$keys
=
array_values
(
$keys
);
$this
->
assertEqual
(
$expect
,
$keys
);
}
}
Event Timeline
Log In to Comment