1<?php 2/** 3 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures 4 * all the essential functionalities required for any enterprise. 5 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com 6 * 7 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of 8 * the GNU General Public License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 12 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * See the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along with this program; 16 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA 18 */ 19 20/** 21 * @group ohrmWidget 22 */ 23class ohrmReportWidgetAgeGroupTest extends PHPUnit\Framework\TestCase 24{ 25 /** 26 * @var ohrmReportWidgetAgeGroup 27 */ 28 private $ohrmReportWidgetAgeGroup = null; 29 30 protected function setUp(): void 31 { 32 $this->ohrmReportWidgetAgeGroup = $this->getMockBuilder(ohrmReportWidgetAgeGroup::class) 33 ->setMethods(['configure']) 34 ->getMock(); 35 } 36 37 /** 38 * @dataProvider generateWhereClausePartDataProvider 39 * @param $value 40 * @param $expected 41 */ 42 public function testGenerateWhereClausePart($value, $expected) 43 { 44 $this->ohrmReportWidgetAgeGroup->setWhereClauseCondition($value['comparision']); 45 $returnValue = $this->ohrmReportWidgetAgeGroup->generateWhereClausePart( 46 'datediff(current_date(), hs_hr_employee.emp_birthday)/365', 47 $value 48 ); 49 $this->assertEquals($expected, $returnValue); 50 } 51 52 /** 53 * @return Generator 54 */ 55 public function generateWhereClausePartDataProvider() 56 { 57 // < 58 yield [ 59 [ 60 'comparision' => '1', 61 'value1' => '20', 62 'value2' => '' 63 ], 64 "datediff(current_date(), hs_hr_employee.emp_birthday)/365 < '20'" 65 ]; 66 67 // > 68 yield [ 69 [ 70 'comparision' => '2', 71 'value1' => '30', 72 'value2' => '' 73 ], 74 "datediff(current_date(), hs_hr_employee.emp_birthday)/365 > '30'" 75 ]; 76 77 // BETWEEN 78 yield [ 79 [ 80 'comparision' => '3', 81 'value1' => '20', 82 'value2' => '30' 83 ], 84 "( datediff(current_date(), hs_hr_employee.emp_birthday)/365 BETWEEN '20' AND '30' )" 85 ]; 86 } 87 88 public function testGenerateWhereClausePartWithoutSetWhereClauseCondition() 89 { 90 $returnValue = $this->ohrmReportWidgetAgeGroup->generateWhereClausePart( 91 'datediff(current_date(), hs_hr_employee.emp_birthday)/365', 92 [ 93 'comparision' => '1', 94 'value1' => '20', 95 'value2' => '' 96 ] 97 ); 98 $this->assertNull($returnValue); 99 } 100 101 /** 102 * @dataProvider generateWhereClausePartWithSqlDataProvider 103 * @param $value 104 * @param $expected 105 */ 106 public function testGenerateWhereClausePartWithSql($value, $expected) 107 { 108 $this->ohrmReportWidgetAgeGroup->setWhereClauseCondition($value['comparision']); 109 $returnValue = $this->ohrmReportWidgetAgeGroup->generateWhereClausePart( 110 'datediff(current_date(), hs_hr_employee.emp_birthday)/365', 111 $value 112 ); 113 $this->assertEquals($expected, $returnValue); 114 } 115 116 /** 117 * @return Generator 118 */ 119 public function generateWhereClausePartWithSqlDataProvider() 120 { 121 // < 122 yield [ 123 [ 124 'comparision' => '1', 125 'value1' => '1;DELETE FROM `hs_hr_employee` WHERE `hs_hr_employee`.`emp_number` = "1";', 126 'value2' => '' 127 ], 128 'datediff(current_date(), hs_hr_employee.emp_birthday)/365 < \'1;DELETE FROM `hs_hr_employee` WHERE `hs_hr_employee`.`emp_number` = \"1\";\'', 129 ]; 130 131 // > 132 yield [ 133 [ 134 'comparision' => '2', 135 'value1' => '1;DELETE FROM `hs_hr_employee` WHERE `hs_hr_employee`.`emp_number` = "1";', 136 'value2' => '' 137 ], 138 'datediff(current_date(), hs_hr_employee.emp_birthday)/365 > \'1;DELETE FROM `hs_hr_employee` WHERE `hs_hr_employee`.`emp_number` = \"1\";\'', 139 ]; 140 141 // BETWEEN 142 yield [ 143 [ 144 'comparision' => '3', 145 'value1' => '1;DELETE FROM `hs_hr_employee` WHERE `hs_hr_employee`.`emp_number` = "1";', 146 'value2' => '30' 147 ], 148 '( datediff(current_date(), hs_hr_employee.emp_birthday)/365 BETWEEN \'1;DELETE FROM `hs_hr_employee` WHERE `hs_hr_employee`.`emp_number` = \"1\";\' AND \'30\' )' 149 ]; 150 } 151} 152