diff --git a/src/OpenFoodFacts.php b/src/OpenFoodFacts.php index 88ec072..daa0273 100644 --- a/src/OpenFoodFacts.php +++ b/src/OpenFoodFacts.php @@ -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']); diff --git a/tests/GeographyTest.php b/tests/GeographyTest.php new file mode 100644 index 0000000..49ed89b --- /dev/null +++ b/tests/GeographyTest.php @@ -0,0 +1,34 @@ +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']); + } +}