|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Grayloon\Magento\Tests; |
| 4 | + |
| 5 | +use Grayloon\Magento\Magento; |
| 6 | +use Illuminate\Support\Facades\Config; |
| 7 | + |
| 8 | +class MagentoTest extends TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * Test by configuring the settings in the constructor. |
| 12 | + * |
| 13 | + * @return void |
| 14 | + **/ |
| 15 | + public function test_by_configuring_the_settings_in_the_constructor() |
| 16 | + { |
| 17 | + $api = new Magento('baseUrl-constructor', 'token-constructor', 'version-constructor', 'basePath-constructor', 'storeCode-constructor'); |
| 18 | + |
| 19 | + $this->assertEquals($api->baseUrl, 'baseUrl-constructor'); |
| 20 | + $this->assertEquals($api->token, 'token-constructor'); |
| 21 | + $this->assertEquals($api->version, 'version-constructor'); |
| 22 | + $this->assertEquals($api->basePath, 'basePath-constructor'); |
| 23 | + $this->assertEquals($api->storeCode, 'storeCode-constructor'); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Test by configuring the settings in the laravel configs. |
| 28 | + * |
| 29 | + * @return void |
| 30 | + **/ |
| 31 | + public function test_by_configuring_the_settings_in_the_laravel_configs() |
| 32 | + { |
| 33 | + Config::set('magento.base_url', 'baseUrl-config'); |
| 34 | + Config::set('magento.token', 'token-config'); |
| 35 | + Config::set('magento.version', 'version-config'); |
| 36 | + Config::set('magento.base_path', 'basePath-config'); |
| 37 | + Config::set('magento.store_code', 'storeCode-config'); |
| 38 | + |
| 39 | + $api = new Magento(); |
| 40 | + |
| 41 | + $this->assertEquals($api->baseUrl, 'baseUrl-config'); |
| 42 | + $this->assertEquals($api->token, 'token-config'); |
| 43 | + $this->assertEquals($api->version, 'version-config'); |
| 44 | + $this->assertEquals($api->basePath, 'basePath-config'); |
| 45 | + $this->assertEquals($api->storeCode, 'storeCode-config'); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Test without configuring the settings. |
| 50 | + * |
| 51 | + * @return void |
| 52 | + **/ |
| 53 | + public function test_without_configuring_the_settings() |
| 54 | + { |
| 55 | + $api = new Magento(); |
| 56 | + |
| 57 | + $this->assertNull($api->baseUrl); |
| 58 | + $this->assertNull($api->token); |
| 59 | + |
| 60 | + $defaultVersion = 'V1'; |
| 61 | + $this->assertEquals($api->version, $defaultVersion); |
| 62 | + |
| 63 | + $defaultBasePath = 'rest'; |
| 64 | + $this->assertEquals($api->basePath, $defaultBasePath); |
| 65 | + |
| 66 | + $defaultStoreCode = 'all'; |
| 67 | + $this->assertEquals($api->storeCode, $defaultStoreCode); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Test by configuring the settings in the constructor have priority. |
| 72 | + * |
| 73 | + * @return void |
| 74 | + **/ |
| 75 | + public function test_by_configuring_the_settings_in_the_constructor_have_priority() |
| 76 | + { |
| 77 | + Config::set('magento.base_url', 'baseUrl-config'); |
| 78 | + Config::set('magento.token', 'token-config'); |
| 79 | + Config::set('magento.version', 'version-config'); |
| 80 | + Config::set('magento.base_path', 'basePath-config'); |
| 81 | + Config::set('magento.store_code', 'storeCode-config'); |
| 82 | + |
| 83 | + $api = new Magento('baseUrl-constructor', 'token-constructor', 'version-constructor', 'basePath-constructor', 'storeCode-constructor'); |
| 84 | + |
| 85 | + $this->assertEquals($api->baseUrl, 'baseUrl-constructor'); |
| 86 | + $this->assertEquals($api->token, 'token-constructor'); |
| 87 | + $this->assertEquals($api->version, 'version-constructor'); |
| 88 | + $this->assertEquals($api->basePath, 'basePath-constructor'); |
| 89 | + $this->assertEquals($api->storeCode, 'storeCode-constructor'); |
| 90 | + } |
| 91 | +} |
0 commit comments