File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ protected function _prepareColumns()
113113
114114 /* @var $adminUsers FireGento_AdminMonitoring_Model_System_Config_Source_Admin_User */
115115 $ adminUsers = Mage::getModel ('firegento_adminmonitoring/system_config_source_admin_user ' );
116- $ userOptions = $ adminUsers ->toOptionHash ();
116+ $ userOptions = $ adminUsers ->toOptionHash (false );
117117 $ this ->addColumn ('user_id ' , array (
118118 'header ' => $ this ->getMonitoringHelper ()->__ ('User ' ),
119119 'index ' => 'user_id ' ,
Original file line number Diff line number Diff line change @@ -32,9 +32,10 @@ class FireGento_AdminMonitoring_Model_System_Config_Source_Admin_User
3232 /**
3333 * Retrieve the option array
3434 *
35+ * @param bool $withEmpty Flag if empty value should be added
3536 * @return array
3637 */
37- public function toOptionArray ()
38+ public function toOptionArray ($ withEmpty = true )
3839 {
3940 if (null === $ this ->_options ) {
4041 $ userCollection = Mage::getModel ('admin/user ' )->getCollection ();
@@ -45,6 +46,13 @@ public function toOptionArray()
4546 'label ' => $ user ->getData ('username ' ),
4647 );
4748 }
49+
50+ if ($ withEmpty ) {
51+ array_unshift ($ this ->_options , array (
52+ 'value ' => '' ,
53+ 'label ' => $ this ->_getHelper ()->__ ('No admin user ' )
54+ ));
55+ }
4856 }
4957
5058 return $ this ->_options ;
Original file line number Diff line number Diff line change @@ -32,9 +32,10 @@ class FireGento_AdminMonitoring_Model_System_Config_Source_History_Action
3232 /**
3333 * Retrieve the option array
3434 *
35+ * @param bool $withEmpty Flag if empty value should be added
3536 * @return array
3637 */
37- public function toOptionArray ()
38+ public function toOptionArray ($ withEmpty = true )
3839 {
3940 if (null === $ this ->_options ) {
4041 $ this ->_options = array (
Original file line number Diff line number Diff line change @@ -32,19 +32,20 @@ class FireGento_AdminMonitoring_Model_System_Config_Source_History_Status
3232 /**
3333 * Retrieve the option array
3434 *
35+ * @param bool $withEmpty Flag if empty value should be added
3536 * @return array
3637 */
37- public function toOptionArray ()
38+ public function toOptionArray ($ withEmpty = true )
3839 {
3940 if (null === $ this ->_options ) {
4041 $ this ->_options = array (
4142 array (
4243 'value ' => FireGento_AdminMonitoring_Helper_Data::STATUS_SUCCESS ,
43- 'label ' => Mage:: helper ( ' firegento_adminmonitoring ' )->__ ('Success ' ),
44+ 'label ' => $ this -> _getHelper ( )->__ ('Success ' ),
4445 ),
4546 array (
4647 'value ' => FireGento_AdminMonitoring_Helper_Data::STATUS_FAILURE ,
47- 'label ' => Mage:: helper ( ' firegento_adminmonitoring ' )->__ ('Failure ' ),
48+ 'label ' => $ this -> _getHelper ( )->__ ('Failure ' ),
4849 )
4950 );
5051 }
Original file line number Diff line number Diff line change @@ -36,18 +36,20 @@ abstract class FireGento_AdminMonitoring_Model_System_Config_Source_SourceAbstra
3636 /**
3737 * Retrieve the option array
3838 *
39+ * @param bool $withEmpty Flag if empty value should be added
3940 * @return array
4041 */
41- abstract public function toOptionArray ();
42+ abstract public function toOptionArray ($ withEmpty = true );
4243
4344 /**
4445 * Retrieve the option hash
4546 *
47+ * @param bool $withEmpty Flag if empty value should be added
4648 * @return array
4749 */
48- public function toOptionHash ()
50+ public function toOptionHash ($ withEmpty = true )
4951 {
50- $ options = $ this ->toOptionArray ();
52+ $ options = $ this ->toOptionArray ($ withEmpty );
5153 $ optionHash = array ();
5254
5355 foreach ($ options as $ option ) {
@@ -56,4 +58,14 @@ public function toOptionHash()
5658
5759 return $ optionHash ;
5860 }
61+
62+ /**
63+ * Retrieve the helper instance
64+ *
65+ * @return FireGento_AdminMonitoring_Helper_Data
66+ */
67+ protected function _getHelper ()
68+ {
69+ return Mage::helper ('firegento_adminmonitoring ' );
70+ }
5971}
Original file line number Diff line number Diff line change @@ -66,6 +66,19 @@ public function toOptionArray()
6666 );
6767 }
6868
69+ /**
70+ * @test
71+ * @loadFixture ~FireGento_AdminMonitoring/default
72+ * @loadExpectations
73+ */
74+ public function toOptionArrayWithoutEmpty ()
75+ {
76+ $ this ->assertEquals (
77+ $ this ->expected ('options ' )->getResult (),
78+ $ this ->_model ->toOptionArray (false )
79+ );
80+ }
81+
6982 /**
7083 * @test
7184 * @loadFixture ~FireGento_AdminMonitoring/default
@@ -78,4 +91,17 @@ public function toOptionHash()
7891 $ this ->_model ->toOptionHash ()
7992 );
8093 }
94+
95+ /**
96+ * @test
97+ * @loadFixture ~FireGento_AdminMonitoring/default
98+ * @loadExpectations
99+ */
100+ public function toOptionHashWithoutEmpty ()
101+ {
102+ $ this ->assertEquals (
103+ $ this ->expected ('options ' )->getResult (),
104+ $ this ->_model ->toOptionHash (false )
105+ );
106+ }
81107}
Original file line number Diff line number Diff line change 11options :
22 result :
3+ - value : ' '
4+ label : ' No admin user'
35 - value : 1
46 label : admin
Original file line number Diff line number Diff line change 1+ options :
2+ result :
3+ - value : 1
4+ label : admin
Original file line number Diff line number Diff line change 11options :
22 result :
3+ ' ' : No admin user
34 1 : admin
Original file line number Diff line number Diff line change 1+ options :
2+ result :
3+ 1 : admin
You can’t perform that action at this time.
0 commit comments