1<?php
2
3/**
4 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
5 * all the essential functionalities required for any enterprise.
6 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
7 *
8 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
9 * the GNU General Public License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA  02110-1301, USA
19 */
20require_once sfConfig::get('sf_test_dir') . '/util/TestDataService.php';
21
22/**
23 * @group Recruitment
24 */
25class RecruitmentAttachmentDaoTest extends PHPUnit_Framework_TestCase {
26
27    private $recruitmentAttachmentDao;
28    protected $fixture;
29
30    /**
31     * Set up method
32     */
33    protected function setUp() {
34
35        $this->recruitmentAttachmentDao = new RecruitmentAttachmentDao();
36        $this->fixture = sfConfig::get('sf_plugins_dir') . '/orangehrmRecruitmentPlugin/test/fixtures/CandidateDao.yml';
37        TestDataService::populate($this->fixture);
38    }
39
40    /**
41     *
42     */
43    public function testSaveVacancyAttachment() {
44
45        $file = tmpfile();
46        fwrite($file, "writing to tempfile");
47        fseek($file, 0);
48        $resume = new JobVacancyAttachment();
49        $resume->id = 5;
50        $resume->vacancyId = 1;
51        $resume->fileName = "abc.txt";
52        $resume->fileType = ".txt";
53        $resume->fileSize = '512';
54        $this->recruitmentAttachmentDao->saveVacancyAttachment($resume);
55
56        $resume = TestDataService::fetchObject('JobVacancyAttachment', 5);
57        $this->assertNotNull($resume->getId());
58        $this->assertEquals($resume->getFileName(), "abc.txt");
59        $this->assertEquals($resume->getFileType(), ".txt");
60        $this->assertEquals($resume->getFileSize(), '512');
61    }
62
63    /**
64     *
65     */
66    public function testSaveVacancyAttachmentForNullId() {
67
68        TestDataService::truncateSpecificTables(array('JobVacancyAttachment'));
69
70        $file = tmpfile();
71        fwrite($file, "writing to tempfile");
72        fseek($file, 0);
73        $resume = new JobVacancyAttachment();
74        $resume->setId(null);
75        $resume->setVacancyId(1);
76        $resume->setFileType('.txt');
77        $resume->setFileName('xyz.txt');
78        $resume->setFileSize('512');
79        $return = $this->recruitmentAttachmentDao->saveVacancyAttachment($resume);
80        $this->assertTrue($return);
81    }
82
83    /**
84     *
85     */
86    public function testSaveCandidateAttachment() {
87
88        $file = tmpfile();
89        fwrite($file, "writing to tempfile");
90        fseek($file, 0);
91        $resume = new JobCandidateAttachment();
92        $resume->id = 5;
93        $resume->candidateId = 1;
94        $resume->fileName = "abc.txt";
95        $resume->fileType = ".txt";
96        $resume->fileSize = '512';
97        $this->recruitmentAttachmentDao->saveCandidateAttachment($resume);
98
99        $resume = TestDataService::fetchObject('JobCandidateAttachment', 5);
100        $this->assertNotNull($resume->getId());
101        $this->assertEquals($resume->getFileName(), "abc.txt");
102        $this->assertEquals($resume->getFileType(), ".txt");
103        $this->assertEquals($resume->getFileSize(), '512');
104    }
105
106    /**
107     *
108     */
109    public function testSaveCandidateAttachmentForNullId() {
110        TestDataService::truncateSpecificTables(array('JobCandidateAttachment'));
111
112        $file = tmpfile();
113        fwrite($file, "writing to tempfile");
114        fseek($file, 0);
115        $resume = new JobCandidateAttachment();
116        $resume->setId(null);
117        $resume->setCandidateId(1);
118        $resume->setFileName('xyz.txt');
119        $resume->setFileType('.txt');
120        $resume->setFileSize('512');
121        $return = $this->recruitmentAttachmentDao->saveCandidateAttachment($resume);
122        $this->assertTrue($return);
123    }
124
125    /**
126     * Testing getVacancyList
127     */
128    public function testGetVacancyAttachments() {
129
130        $vacancyId = 1;
131        $vacancyList = $this->recruitmentAttachmentDao->getVacancyAttachments($vacancyId);
132        $this->assertTrue($vacancyList[0] instanceof JobVacancyAttachment);
133        $this->assertEquals(sizeof($vacancyList), 2);
134    }
135
136    public function testGetInterviewAttachments() {
137
138        $interviewId = 1;
139        $attachments = $this->recruitmentAttachmentDao->getInterviewAttachments($interviewId);
140        $this->assertTrue($attachments[0] instanceof JobInterviewAttachment);
141        $this->assertEquals(sizeof($attachments), 2);
142    }
143
144    public function testGetVacancyAttachment() {
145
146        $attachId = 1;
147        $attachment = $this->recruitmentAttachmentDao->getVacancyAttachment($attachId);
148        $this->assertTrue($attachment instanceof JobVacancyAttachment);
149        $this->assertEquals($attachment->fileName, 'xyz.txt');
150        $this->assertEquals($attachment->fileSize, 512);
151    }
152
153    public function testGetInterviewAttachment() {
154
155        $attachId = 1;
156        $attachment = $this->recruitmentAttachmentDao->getInterviewAttachment($attachId);
157        $this->assertTrue($attachment instanceof JobInterviewAttachment);
158        $this->assertEquals($attachment->fileName, 'resume.pdf');
159        $this->assertEquals($attachment->fileSize, 512);
160    }
161
162    public function testGetCandidateAttachment() {
163
164        $attachId = 1;
165        $attachment = $this->recruitmentAttachmentDao->getCandidateAttachment($attachId);
166        $this->assertTrue($attachment instanceof JobCandidateAttachment);
167        $this->assertEquals($attachment->fileName, 'xyz.txt');
168        $this->assertEquals($attachment->fileSize, 512);
169    }
170
171}
172
173