Skip to content

Commit

Permalink
Merge pull request #1 from JobBrander/multiple_cats
Browse files Browse the repository at this point in the history
Updating for arrays in setter
  • Loading branch information
karllhughes committed Oct 15, 2015
2 parents c021eee + 4d8bbac commit 780a909
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Changelog
All Notable changes to `jobs-muse` will be documented in this file

## 0.2.0 - 2015-10-15

### Added
- Support for multiple parameters in setCategory() and other setters

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing

## 0.1.1 - 2015-08-30

### Added
Expand Down
16 changes: 15 additions & 1 deletion src/Muse.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ public function createJobArray($item)
return $jobs;
}

/**
* Get category or categories
*
* @return string
*/
public function getCategory()
{
if (is_array($this->category)) {
// print_r($this->category); exit;
}
return $this->category;
}

/**
* Get listings path
*
Expand Down Expand Up @@ -181,7 +194,8 @@ public function getQueryString()
}
});

return http_build_query($query_string);
$query = http_build_query($query_string, null, '&');
return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $query);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/src/MuseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ public function testUrlIncludesCategoryWhenProvided()
$this->assertContains($param, $url);
}

public function testUrlIncludesMultipleCategoriesWhenProvided()
{
$params = [];
$array = [
0 => uniqid().' '.uniqid(),
1 => uniqid().' '.uniqid(),
2 => uniqid().' '.uniqid(),
];
foreach ($array as $key => $category) {
$params[] = urlencode('job_category[]').'='.urlencode($array[$key]);
}

$url = $this->client->setCategory($array)->getUrl();

foreach ($params as $param) {
$this->assertContains($param, $url);
}
}

public function testUrlNotIncludesCategoryWhenNotProvided()
{
$param = urlencode('job_category[]').'=';
Expand Down

0 comments on commit 780a909

Please sign in to comment.