From 7d660abc3c87a01087d4a78fe8955ade73e705c3 Mon Sep 17 00:00:00 2001 From: Tom Phillips Date: Mon, 24 Feb 2020 16:35:10 -0500 Subject: [PATCH] Allow for required files to correctly check for URLs and content. --- src/Services/ApplicationService.php | 40 ++++++++++++ tests/Services/ApplicationServiceTest.php | 80 +++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/src/Services/ApplicationService.php b/src/Services/ApplicationService.php index 6edefc1..483e504 100644 --- a/src/Services/ApplicationService.php +++ b/src/Services/ApplicationService.php @@ -125,10 +125,50 @@ public function hasRequiredValue($postVars, $keys) $requiredKey = $this->findKey($key, $postVars); if (array_key_exists($requiredKey, $postVars) && $postVars[$requiredKey] !== '') return true; } + + if ($this->_hasRequiredValuesForFiles($postVars, $key)) return true; return false; } + /** + * Previously, Greenhouse only accepted files in one way via resume and resume_text. Since, they + * included the ability to send files by linking to them or via binary content. However, they still + * only mark the resume as required using the 'resume' field in the jobs description. This method also + * checks the alternatives. The alternatives are: + * _content and _content_filename + * _url and _url_filename + * If either of these are included, the requirement should pass. This is the case for resume + * and cover_letter; and also the case for custom questions which may also contain a file. + * + * @params Array $postVars Greenhouse post parameters + * @params string $key The key we are validating + * @return boolean + */ + private function _hasRequiredValuesForFiles($postVars, $key) + { + $contentKey = "${key}_content"; + $contentFilenameKey = "${key}_content_filename"; + $urlKey = "${key}_url"; + $urlFilenameKey = "${key}_url_filename"; + + if (array_key_exists($contentKey, $postVars) && + array_key_exists($contentFilenameKey, $postVars) && + $postVars[$contentKey] !== '' && + $postVars[$contentFilenameKey] !== '') { + return true; + } + + if (array_key_exists($urlKey, $postVars) && + array_key_exists($urlFilenameKey, $postVars) && + $postVars[$urlKey] !== '' && + $postVars[$urlFilenameKey] !== '') { + return true; + } + + return false; + } + /** * This fixes an issue where the Greenhouse API returns required multiselects as but we require * the user to submit it as , thus making the system think the required field is not set. This diff --git a/tests/Services/ApplicationServiceTest.php b/tests/Services/ApplicationServiceTest.php index 80f9975..e2b2939 100644 --- a/tests/Services/ApplicationServiceTest.php +++ b/tests/Services/ApplicationServiceTest.php @@ -253,6 +253,86 @@ public function testHasRequiredValueMultipleZero() $this->assertTrue($this->appService->hasRequiredValue($postVars, $keys)); } + + public function testHasBinaryFilenameFieldPass() + { + $postVars = array('foo' => '', 'foo_content' => 'abce', 'foo_content_filename' => 'test.pdf'); + $keys = array('foo'); + + $this->assertTrue($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasBinaryFilenameFieldFailContentBlank() + { + $postVars = array('foo' => '', 'foo_content' => '', 'foo_content_filename' => 'test.pdf'); + $keys = array('foo'); + + $this->assertFalse($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasBinaryFilenameFieldFailContentNotIncluded() + { + $postVars = array('foo' => '', 'foo_content_filename' => 'test.pdf'); + $keys = array('foo'); + + $this->assertFalse($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasBinaryFilenameFieldFailFilenameBlank() + { + $postVars = array('foo' => '', 'foo_content' => 'abce', 'foo_content_filename' => ''); + $keys = array('foo'); + + $this->assertFalse($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasBinaryFilenameFieldFailFilenameNotIncluded() + { + $postVars = array('foo' => '', 'foo_content' => 'abcde'); + $keys = array('foo'); + + $this->assertFalse($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasUrlFilenameFieldPass() + { + $postVars = array('foo' => '', 'foo_url' => 'http://t.co', 'foo_url_filename' => 'test.pdf'); + $keys = array('foo'); + + $this->assertTrue($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasUrlFilenameFieldFailUrlBlank() + { + $postVars = array('foo' => '', 'foo_url' => '', 'foo_url_filename' => 'test.pdf'); + $keys = array('foo'); + + $this->assertFalse($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasUrlFilenameFieldFailUrlFilenameBlank() + { + $postVars = array('foo' => '', 'foo_url' => 'http://t.co', 'foo_url_filename' => ''); + $keys = array('foo'); + + $this->assertFalse($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasUrlFilenameFieldFailUrlNotIncluded() + { + $postVars = array('foo' => '', 'foo_url_filename' => 'test.pdf'); + $keys = array('foo'); + + $this->assertFalse($this->appService->hasRequiredValue($postVars, $keys)); + } + + public function testHasUrlFilenameFieldFailUrlFilenameNotIncluded() + { + $postVars = array('foo' => '', 'foo_url' => 'http://t.co'); + $keys = array('foo'); + + $this->assertFalse($this->appService->hasRequiredValue($postVars, $keys)); + } public function testGetRequiredFields() {