Skip to content

Commit

Permalink
Merge pull request #324 from zendesk/kcasas/MI-1528-helpcenter-articl…
Browse files Browse the repository at this point in the history
…es-search

[MI-1528] HelpCenter Articles Search
  • Loading branch information
kcasas authored May 15, 2017
2 parents 8fde2ef + 7a2c5d4 commit f2140aa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Zendesk/API/Resources/HelpCenter/Articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Zendesk\API\Exceptions\RouteException;
use Zendesk\API\Traits\Resource\Defaults;
use Zendesk\API\Traits\Resource\Locales;
use Zendesk\API\Traits\Resource\Search;

/**
* Class Articles
Expand All @@ -14,6 +15,7 @@ class Articles extends ResourceAbstract
{
use Defaults;
use Locales;
use Search;

/**
* @{inheritdoc}
Expand Down
30 changes: 30 additions & 0 deletions src/Zendesk/API/Traits/Resource/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Zendesk\API\Traits\Resource;

use Zendesk\API\Exceptions\RouteException;

trait Search
{
/**
* Used to access the search endpoint of Resources
*
* @param array $params query parameters
* @return null|\stdClass
*/
public function search(array $params)
{
try {
$route = $this->getRoute(__FUNCTION__, $params);
} catch (RouteException $e) {
if (! isset($this->resourceName)) {
$this->resourceName = $this->getResourceNameFromClass();
}

$route = $this->resourceName . '/search.json';
$this->setRoute(__FUNCTION__, $route);
}

return $this->client->get($route, $params);
}
}
2 changes: 1 addition & 1 deletion tests/Zendesk/API/UnitTests/Core/AppInstallationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testUpdate()
]
];

$id = $faker->randomNumber();
$id = $faker->randomNumber(null, true);

$this->assertEndpointCalled(function () use ($id, $params) {
$this->client->appInstallations()->update($id, $params);
Expand Down
15 changes: 14 additions & 1 deletion tests/Zendesk/API/UnitTests/HelpCenter/ArticlesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Zendesk\API\UnitTests\HelpCenter;

use Zendesk\API\Resources\HelpCenter\Categories;
use Faker\Factory;
use Zendesk\API\UnitTests\BasicTest;

class ArticlesTest extends BasicTest
Expand Down Expand Up @@ -65,4 +65,17 @@ public function testUpdateArticleSourceLocaleNoId()
$this->client->helpCenter->articles(1)->updateSourceLocale(null, 'fr');
}, 'help_center/articles/1/source_locale.json', 'PUT', ['postFields' => ['article_locale' => 'fr']]);
}

/**
* Tests if the Search on Articles accesses the correct endpoint and that it uses the params provided
*/
public function testSearch()
{
$faker = Factory::create();
$params = ['query' => $faker->word];

$this->assertEndpointCalled(function () use ($params) {
$this->client->helpCenter->articles()->search($params);
}, 'help_center/articles/search.json', 'GET', ['queryParams' => $params]);
}
}

0 comments on commit f2140aa

Please sign in to comment.