Skip to content

Commit

Permalink
Merge pull request #22 from openfoodfacts/explicit_geography
Browse files Browse the repository at this point in the history
feat: Explicit geography
  • Loading branch information
epalmans authored May 1, 2024
2 parents 863b10b + 98fe63f commit 0903b12
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/OpenFoodFacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class OpenFoodFacts extends OpenFoodFactsApiWrapper
{
protected $max_results;

public function __construct(Container $app)
public function __construct(Container $app, string $geography = null)
{
parent::__construct([
'geography' => $app['config']->get('openfoodfacts.geography'),
'geography' => $geography ?? $app['config']->get('openfoodfacts.geography'),
'app' => $app['config']->get('app.name'),
], $app['cache.store']);

Expand Down
34 changes: 34 additions & 0 deletions tests/GeographyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace OpenFoodFacts\Laravel\Tests;

use Illuminate\Support\Facades\Config;
use OpenFoodFacts\Laravel\Facades\OpenFoodFacts as OpenFoodFactsFacade;
use OpenFoodFacts\Laravel\OpenFoodFacts;

class GeographyTest extends Base\FacadeTestCase
{
/** @test */
public function it_returns_different_content_based_on_geography_parameter()
{
$barcode = '8714200216964';

$instanceWorld = app()->make(OpenFoodFacts::class);
$product_default_content = $instanceWorld->barcode($barcode);

$instanceNL = app()->make(OpenFoodFacts::class, ['geography' => 'nl']);
$product_dutch_content = $instanceNL->barcode($barcode);

$this->assertEquals($product_default_content['_id'], $product_dutch_content['_id']);
$this->assertNotEquals($product_default_content, $product_dutch_content);
}

/** @test */
public function it_returns_geo_specific_content_through_config_setting()
{
Config::set('openfoodfacts.geography', 'nl');
$product_dutch_content = OpenFoodFactsFacade::barcode('8714200216964');

$this->assertStringContainsString('front_nl.', $product_dutch_content['image_url']);
}
}

0 comments on commit 0903b12

Please sign in to comment.