<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CorporateDirectoryWebServiceWrapperTest
 *
 * @author emma
 */
require_once ROOT_PATH . "/lib/confs/Conf.php";

class CorporateDirectoryWebServiceWrapperTest extends PHPUnit_Framework_TestCase {

    protected $fixture;
    protected $manager;
    protected $corporateDirectoryWebServiceWrapper;

    public static function setupBeforeClass() {
        WSManager::resetConfiguration();
    }

    /**
     * Set up method
     */
    protected function setUp() {
        $this->corporateDirectoryWebServiceWrapper = new CorporateDirectoryWebServiceWrapper();
        $this->fixture = sfConfig::get('sf_plugins_dir') . '/orangehrmCorporateDirectoryPlugin/test/fixtures/EmployeeDirectoryWrapperData.yml';
        $this->manager = new WSManager();
        $this->helper = new WSHelper();

        PHPUnit_Framework_Error_Warning::$enabled = FALSE;

        PHPUnit_Framework_Error_Notice::$enabled = FALSE;
    }

    public function getExpectedEmployeeList($base64TestStringForEmp1, $base64TestStringForEmp2) {
        $array = array(
            array(
                'emp_number' => 2,
                'employee_id' => 'Z0002',
                'emp_firstname' => 'Saman',
                'emp_lastname' => 'Fernando',
                'home_telephone' => null,
                'work_telephone' => null,
                'mobile' => null,
                'work_email' => null,
                'other_email' => null,
                'profile_image_url' => '/usr/local/bin/phpunit/phpunit/directory/viewDirectoryPhoto/empNumber/2',
                'terminated' => null,
                'profile_picture' => array(
                    'image_string' => $base64TestStringForEmp1,
                    'image_type' => 'image/gif'),
                'location_id' => 1,
                'job_title_id' => 2,
                'subunit_id' => null,
            ),
            array(
                'emp_number' => 4,
                'employee_id' => null,
                'emp_firstname' => 'Chuck',
                'emp_lastname' => 'Fernando',
                'home_telephone' => null,
                'work_telephone' => null,
                'mobile' => null,
                'work_email' => null,
                'other_email' => null,
                'profile_image_url' => '/usr/local/bin/phpunit/phpunit/directory/viewDirectoryPhoto/empNumber/4',
                'terminated' => null,
                'profile_picture' => null,
                'location_id' => 2,
                'job_title_id' => 3,
                'subunit_id' => null,
            ),
            array(
                'emp_number' => 1,
                'employee_id' => 'Z0001',
                'emp_firstname' => 'Saman',
                'emp_lastname' => 'Herath',
                'home_telephone' => null,
                'work_telephone' => null,
                'mobile' => null,
                'work_email' => null,
                'other_email' => null,
                'profile_image_url' => '/usr/local/bin/phpunit/phpunit/directory/viewDirectoryPhoto/empNumber/1',
                'terminated' => null,
                'profile_picture' => null,
                'location_id' => 1,
                'job_title_id' => 1,
                'subunit_id' => null,
            ),
            array(
                'emp_number' => 5,
                'employee_id' => null,
                'emp_firstname' => 'Pasindu',
                'emp_lastname' => 'Jayasekara',
                'home_telephone' => null,
                'work_telephone' => null,
                'mobile' => null,
                'work_email' => null,
                'other_email' => null,
                'profile_image_url' => '/usr/local/bin/phpunit/phpunit/directory/viewDirectoryPhoto/empNumber/5',
                'terminated' => null,
                'profile_picture' => null,
                'location_id' => null,
                'job_title_id' => 4,
                'subunit_id' => null,
            ),
            array(
                'emp_number' => 6,
                'employee_id' => null,
                'emp_firstname' => 'kamal',
                'emp_lastname' => 'jayasinghe',
                'home_telephone' => '3333',
                'work_telephone' => '5555',
                'mobile' => '4444',
                'work_email' => 'bbb@bbb.com',
                'other_email' => 'aaa@aaa.com',
                'profile_image_url' => '/usr/local/bin/phpunit/phpunit/directory/viewDirectoryPhoto/empNumber/6',
                'terminated' => null,
                'profile_picture' => null,
                'location_id' => null,
                'job_title_id' => 4,
                'subunit_id' => null,
            ),
            array(
                'emp_number' => 3,
                'employee_id' => null,
                'emp_firstname' => 'Ashan',
                'emp_lastname' => 'Perera',
                'home_telephone' => null,
                'work_telephone' => null,
                'mobile' => null,
                'work_email' => null,
                'other_email' => null,
                'profile_image_url' => '/usr/local/bin/phpunit/phpunit/directory/viewDirectoryPhoto/empNumber/3',
                'terminated' => null,
                'profile_picture' => array(
                    'image_string' => $base64TestStringForEmp2,
                    'image_type' => 'image/jpeg'),
                'location_id' => 1,
                'job_title_id' => 2,
                'subunit_id' => null,
            ),
        );
        return $array;
    }

    public function testCallGetCorporateDirectoryEmployeeDetailsMethod() {
        TestDataService::populate($this->fixture);

        $employeeService = new EmployeeService();
        $empPicture = $employeeService->getEmployeePicture(2);
        $base64TestStringForEmp1 = 'R0lGODlhCgAKALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//////ywAAAAACgAKAAAEClDJSau9OOvNe44AOw==';
        $decodedBase64String = base64_decode($base64TestStringForEmp1);
        $empPicture->setPicture($decodedBase64String);
        $empPicture->save();

        $empPicture = $employeeService->getEmployeePicture(3);
        $base64TestStringForEmp2 = '/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAHcAdwMBEQACEQEDEQH/xAAbAAEBAQEAAwEAAAAAAAAAAAAABAUGAQIDB//EAD8QAAEDAwAEBw8DAwUAAAAAAAECAwQABREGEiGTExQVMTNBUSIyNVNUZHFzdIGxsrPR4QdhciORoSQ0UmKC/8QAGAEBAQEBAQAAAAAAAAAAAAAAAAQDAQL/xAAqEQEAAQIDCAMBAAMBAAAAAAAAAQIDBBOxMTNRYnGBkcERFKEhImHREv/aAAwDAQACEQMRAD8A/bq6FAoFAoFAoMuBf4NwvEu2RFKcciNpW44kdxtUpOqD1kFBz2c3PmuC96VHYU2l99ptTh1UBawkqPYM85oPRU6IlwtqlMBwAkoLgBAHOcZ6qD6sutvtpcZcQ42ralaFZB99dHvQKBQKBQKBQZV40lsdkBN2usSKf+Djo1j6E85/tQR6PaY2fSBpyRAeIiJOql9/DQcPXqpUdbZ2kAf5rg1+UoHl0XfJ+9dDlKB5dF3yfvQYzLrCNMZlwMqKIrltYYSvh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Lmlq3pk2t6HEtjcnhUFxaSOEcXgDO0AY6qBedF7lM/S2Ho6ylnlBmPEbUCvCMtqQVbf8AyaDW0rs8u6ztHnooQUQLmiS9rKx3ASoHHadtB0VdCgUENk8HJ9Y79RVb4nedo0hTi972jSF1YJkN98CXH2V35TQWN9Gn+I+FBLbukm+0n5U1rd2UdPcqL+yjp7lZWScoFAoFAoFAoFAoIbJ4OT6x36iq3xO87RpCnF73tGkLqwTIb74DuPsrvymgsb6NP8R8KCW3dJN9pPyprW7so6e5UX9lHT3Kysk5QKBQKBQKBQKBQQ2Twcn1jv1FVvid52jSFOL3vaNIXVgmZ9+dQm0TW1LSFuRnQhJO1RCCdnbXBWw824FIbWlSm8JWEnOqrAOD++CD766Phbukm+0n5U1rd2UdPcqL+yjp7lZWScoFAoFAoFAoFAoIbJ4OT6x36iq3xO87RpCnF73tGkLqwTOR/Va3uztBriuItbcqGnjTS0EhSSjacelOsPfXBX+ntudtmhtsalKWuU61xiQpZyouOHXVk++g17d0k32k/Kmtruyjp7lvfn+UdPcrKxYFAoFAoFAoFAoHNQQ2Twcn1jv1FVRid52jSFOL3vaNIXVgmejzTb7LjLyAttxJStJ5lA7CKD2AATqgYAGMCgmVb4qnFuFrulnKiFEZPuNaReriPj5bRiLkRERP8g5OieLO8V967n3OOjv2bvH8g5OieLO8V96Z9zjofZu8fyDk6J4s7xX3pn3OOh9m7x/IOTonizvFfemfc46H2bvH8g5OieLO8V96Z9zjofZu8fyDk6J4s7xX3pn3OOh9m7x/IOTonizvFfemfc46H2bvH8g5OieLO8V96Z9zjofZu8fyDk6J4s7xX3pn3OOh9m7x/IeOTYni1bxX3pn3OOh9i5x/IfdhluO0lplAQ2nmSKzqqmqfmWVddVdX/qqfmX//2Q==';
        $decodedBase64String = base64_decode($base64TestStringForEmp2);
        $empPicture->setPicture($decodedBase64String);
        $empPicture->save();

        $paramObj = new WSRequestParameters();
        $paramObj->setAppId(1);
        $paramObj->setAppToken('1234567890');
        $paramObj->setMethod('getCorporateDirectoryEmployeeDetails');
        $paramObj->setSessionToken(uniqid('ohrm_ws_session_'));
        $paramObj->setParameters(array('includeTerminate' => 0));
        $paramObj->setRequestMethod('GET');

        $result = $this->manager->callMethod($paramObj);
        $this->assertNotNull($result);
        $this->assertEquals(6, count($result));
        $expectedEmployeeList = $this->getExpectedEmployeeList($base64TestStringForEmp1, $base64TestStringForEmp2);
        foreach ($expectedEmployeeList as $key => $testCase) {
            $this->assertEquals($result[$key], $expectedEmployeeList[$key]);
        }
    }

}
