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 20use Orangehrm\Rest\Http\Request; 21use Orangehrm\Rest\Http\Response; 22 23/** 24 * @group API 25 */ 26class ApiHelpAPITest extends PHPUnit\Framework\TestCase 27{ 28 /** 29 * @var Request 30 */ 31 private $request = null; 32 33 protected function setUp() 34 { 35 $sfEvent = new sfEventDispatcher(); 36 $sfRequest = new sfWebRequest($sfEvent); 37 $this->request = new Request($sfRequest); 38 } 39 40 public function testGetHelpConfigurationWithCategoryAndQuery() 41 { 42 $articleResult = array( 43 array( 44 "name"=> "Admin User Guide", 45 "url"=> "https://opensourcehelp.orangehrm.com/hc/en-us/categories/360002945799-Admin-User-Guide" 46 ), 47 array( 48 "name"=> "Employee User Guide", 49 "url"=> "https://opensourcehelp.orangehrm.com/hc/en-us/categories/360002926580-Employee-User-Guide" 50 ) 51 ); 52 $helpService = $this->getMockBuilder('HelpService') 53 ->setMethods(['getDefaultRedirectUrl','getCategoriesFromSearchQuery','getRedirectUrlList']) 54 ->getMock(); 55 $helpService->expects($this->once()) 56 ->method('getDefaultRedirectUrl') 57 ->will($this->returnValue('https://opensourcehelp.orangehrm.com/hc/en-us')); 58 $helpService->expects($this->once()) 59 ->method('getCategoriesFromSearchQuery') 60 ->with('Admin') 61 ->will($this->returnValue($articleResult)); 62 $params = ['query' => "Admin",'mode'=>'category']; 63 $helpAPI = $this->getMockBuilder('Orangehrm\Rest\Api\User\Help\HelpConfigurationAPI') 64 ->setMethods(['getParameters']) 65 ->setConstructorArgs([$this->request]) 66 ->getMock(); 67 $helpAPI->setHelpService($helpService); 68 $helpAPI->expects($this->once()) 69 ->method('getParameters') 70 ->will($this->returnValue($params)); 71 $actual=$helpAPI->getHelpConfiguration(); 72 $expected= new Response( 73 array( 74 'defaultRedirectUrl'=>'https://opensourcehelp.orangehrm.com/hc/en-us', 75 'redirectUrls'=> $articleResult 76 )); 77 $this->assertEquals($expected,$actual); 78 } 79 80 public function testGetHelpConfigurationWithArticlesInCategoryWithQuery() 81 { 82 $articleResult = array( 83 array( 84 "name"=> "How to Approve Leave by Admin or Supervisor", 85 "url"=> "https://opensourcehelp.orangehrm.com/hc/en-us/articles/360018659479-How-to-Approve-Leave-by-Admin-or-Supervisor" ), 86 array( 87 "name"=> "How to Create Dynamic Reports", 88 "url"=> "https://opensourcehelp.orangehrm.com/hc/en-us/articles/360018591300-How-to-Create-Dynamic-Reports" ) 89 ); 90 $helpService = $this->getMockBuilder('HelpService') 91 ->setMethods(['getDefaultRedirectUrl','getCategoriesFromSearchQuery','getRedirectUrlList']) 92 ->getMock(); 93 $helpService->expects($this->once()) 94 ->method('getDefaultRedirectUrl') 95 ->will($this->returnValue('https://opensourcehelp.orangehrm.com/hc/en-us')); 96 $helpService->expects($this->once()) 97 ->method('getRedirectUrlList') 98 ->with('Admin') 99 ->will($this->returnValue($articleResult)); 100 $params = ['query' => "Admin",'categories'=>array('360002945799')]; 101 $helpAPI = $this->getMockBuilder('Orangehrm\Rest\Api\User\Help\HelpConfigurationAPI') 102 ->setMethods(['getParameters']) 103 ->setConstructorArgs([$this->request]) 104 ->getMock(); 105 $helpAPI->setHelpService($helpService); 106 $helpAPI->expects($this->once()) 107 ->method('getParameters') 108 ->will($this->returnValue($params)); 109 $actual=$helpAPI->getHelpConfiguration(); 110 $expected= new Response( 111 array( 112 'defaultRedirectUrl'=>'https://opensourcehelp.orangehrm.com/hc/en-us', 113 'redirectUrls'=> $articleResult 114 )); 115 $this->assertEquals($expected,$actual); 116 } 117} 118