diff --git a/src/Zendesk/API/Resources/HelpCenter/Articles.php b/src/Zendesk/API/Resources/HelpCenter/Articles.php index 35699ea5..14c105e6 100644 --- a/src/Zendesk/API/Resources/HelpCenter/Articles.php +++ b/src/Zendesk/API/Resources/HelpCenter/Articles.php @@ -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 @@ -14,6 +15,7 @@ class Articles extends ResourceAbstract { use Defaults; use Locales; + use Search; /** * @{inheritdoc} diff --git a/src/Zendesk/API/Traits/Resource/Search.php b/src/Zendesk/API/Traits/Resource/Search.php new file mode 100644 index 00000000..3fc2f0ae --- /dev/null +++ b/src/Zendesk/API/Traits/Resource/Search.php @@ -0,0 +1,30 @@ +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); + } +} diff --git a/tests/Zendesk/API/UnitTests/Core/AppInstallationsTest.php b/tests/Zendesk/API/UnitTests/Core/AppInstallationsTest.php index 4c48940d..fa75e125 100644 --- a/tests/Zendesk/API/UnitTests/Core/AppInstallationsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/AppInstallationsTest.php @@ -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); diff --git a/tests/Zendesk/API/UnitTests/HelpCenter/ArticlesTest.php b/tests/Zendesk/API/UnitTests/HelpCenter/ArticlesTest.php index cc1cc63a..4014281e 100644 --- a/tests/Zendesk/API/UnitTests/HelpCenter/ArticlesTest.php +++ b/tests/Zendesk/API/UnitTests/HelpCenter/ArticlesTest.php @@ -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 @@ -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]); + } }