@@ -72,4 +72,42 @@ public function testGetAllIdsWithBind()
7272 $ this ->_model ->addBindParam ('code ' , 'admin ' );
7373 $ this ->assertEquals (['0 ' ], $ this ->_model ->getAllIds ());
7474 }
75+
76+ /**
77+ * Check add field to select doesn't remove expression field from select.
78+ *
79+ * @return void
80+ */
81+ public function testAddExpressionFieldToSelectWithAdditionalFields ()
82+ {
83+ $ expectedColumns = ['code ' , 'test_field ' ];
84+ $ actualColumns = [];
85+
86+ $ testExpression = new \Zend_Db_Expr ('(sort_order + group_id) ' );
87+ $ this ->_model ->addExpressionFieldToSelect ('test_field ' , $ testExpression , ['sort_order ' , 'group_id ' ]);
88+ $ this ->_model ->addFieldToSelect ('code ' , 'code ' );
89+ $ columns = $ this ->_model ->getSelect ()->getPart (\Magento \Framework \DB \Select::COLUMNS );
90+ foreach ($ columns as $ columnEntry ) {
91+ $ actualColumns [] = $ columnEntry [2 ];
92+ }
93+
94+ $ this ->assertEquals ($ expectedColumns , $ actualColumns );
95+ }
96+
97+ /**
98+ * Check add expression field doesn't remove all fields from select.
99+ *
100+ * @return void
101+ */
102+ public function testAddExpressionFieldToSelectWithoutAdditionalFields ()
103+ {
104+ $ expectedColumns = ['* ' , 'test_field ' ];
105+
106+ $ testExpression = new \Zend_Db_Expr ('(sort_order + group_id) ' );
107+ $ this ->_model ->addExpressionFieldToSelect ('test_field ' , $ testExpression , ['sort_order ' , 'group_id ' ]);
108+ $ columns = $ this ->_model ->getSelect ()->getPart (\Magento \Framework \DB \Select::COLUMNS );
109+ $ actualColumns = [$ columns [0 ][1 ], $ columns [1 ][2 ]];
110+
111+ $ this ->assertEquals ($ expectedColumns , $ actualColumns );
112+ }
75113}
0 commit comments