|
11 | 11 | use Magento\CheckoutAgreements\Model\Agreement as AgreementModel;
|
12 | 12 | use Magento\CheckoutAgreements\Model\AgreementFactory;
|
13 | 13 | use Magento\CheckoutAgreements\Model\ResourceModel\Agreement;
|
| 14 | +use Magento\Config\Model\ResourceModel\Config; |
| 15 | +use Magento\Framework\App\Config\ReinitableConfigInterface; |
| 16 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
14 | 17 | use Magento\Framework\ObjectManagerInterface;
|
| 18 | +use Magento\Store\Api\Data\StoreInterface; |
| 19 | +use Magento\Store\Model\ScopeInterface; |
15 | 20 | use Magento\Store\Model\StoreManagerInterface;
|
16 | 21 | use Magento\TestFramework\Helper\Bootstrap;
|
17 | 22 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
18 | 23 |
|
19 | 24 | class CheckoutAgreementsListTest extends GraphQlAbstract
|
20 | 25 | {
|
| 26 | + private $agreementsXmlConfigPath = 'checkout/options/enable_agreements'; |
| 27 | + |
21 | 28 | /**
|
22 | 29 | * @var ObjectManagerInterface
|
23 | 30 | */
|
24 | 31 | private $objectManager;
|
25 | 32 |
|
| 33 | + /** |
| 34 | + * @var Config |
| 35 | + */ |
| 36 | + private $config; |
| 37 | + |
26 | 38 | protected function setUp()
|
27 | 39 | {
|
28 | 40 | parent::setUp();
|
| 41 | + |
29 | 42 | $this->objectManager = Bootstrap::getObjectManager();
|
| 43 | + $this->config = $this->objectManager->get(Config::class); |
| 44 | + $this->saveAgreementConfig(1); |
30 | 45 | }
|
31 | 46 |
|
32 | 47 | /**
|
@@ -106,6 +121,34 @@ public function testGetAgreementNotSet()
|
106 | 121 | $this->assertCount(0, $agreements);
|
107 | 122 | }
|
108 | 123 |
|
| 124 | + /** |
| 125 | + * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php |
| 126 | + * @magentoApiDataFixture Magento/CheckoutAgreements/_files/agreement_inactive_with_text_content.php |
| 127 | + * @magentoApiDataFixture Magento/Store/_files/second_store.php |
| 128 | + */ |
| 129 | + public function testDisabledAgreements() |
| 130 | + { |
| 131 | + $secondStoreCode = 'fixture_second_store'; |
| 132 | + $agreementsName = 'Checkout Agreement (active)'; |
| 133 | + |
| 134 | + $query = $this->getQuery(); |
| 135 | + $this->assignAgreementsToStore($secondStoreCode, $agreementsName); |
| 136 | + |
| 137 | + /** @var StoreManagerInterface $storeManager */ |
| 138 | + $storeManager = $this->objectManager->get(StoreManagerInterface::class); |
| 139 | + $store = $storeManager->getStore($secondStoreCode); |
| 140 | + $this->saveAgreementConfig(0, $store); |
| 141 | + |
| 142 | + $headerMap['Store'] = $secondStoreCode; |
| 143 | + $response = $this->graphQlQuery($query, [], '', $headerMap); |
| 144 | + |
| 145 | + $this->assertArrayHasKey('checkoutAgreements', $response); |
| 146 | + $agreements = $response['checkoutAgreements']; |
| 147 | + $this->assertCount(0, $agreements); |
| 148 | + |
| 149 | + $this->deleteAgreementConfig($store); |
| 150 | + } |
| 151 | + |
109 | 152 | /**
|
110 | 153 | * @return string
|
111 | 154 | */
|
@@ -145,4 +188,52 @@ private function assignAgreementsToStore(string $storeCode, string $agreementsNa
|
145 | 188 | $agreements->setData('stores', [$store->getId()]);
|
146 | 189 | $agreementsResource->save($agreements);
|
147 | 190 | }
|
| 191 | + |
| 192 | + protected function tearDown() |
| 193 | + { |
| 194 | + parent::tearDown(); |
| 195 | + |
| 196 | + $this->deleteAgreementConfig(); |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * @param int $value |
| 201 | + * @param StoreInterface $store |
| 202 | + */ |
| 203 | + private function saveAgreementConfig(int $value, ?StoreInterface $store = null): void |
| 204 | + { |
| 205 | + $scopeId = $store ? $store->getId() : 0; |
| 206 | + $scope = $store ? ScopeInterface::SCOPE_STORE : ScopeConfigInterface::SCOPE_TYPE_DEFAULT; |
| 207 | + $this->config->saveConfig( |
| 208 | + $this->agreementsXmlConfigPath, |
| 209 | + $value, |
| 210 | + $scope, |
| 211 | + $scopeId |
| 212 | + ); |
| 213 | + |
| 214 | + $this->reinitConfig(); |
| 215 | + } |
| 216 | + |
| 217 | + /** |
| 218 | + * @param StoreInterface $store |
| 219 | + */ |
| 220 | + private function deleteAgreementConfig(?StoreInterface $store = null): void |
| 221 | + { |
| 222 | + $scopeId = $store ? $store->getId() : 0; |
| 223 | + $scope = $store ? ScopeInterface::SCOPE_STORE : ScopeConfigInterface::SCOPE_TYPE_DEFAULT; |
| 224 | + $this->config->deleteConfig( |
| 225 | + $this->agreementsXmlConfigPath, |
| 226 | + $scope, |
| 227 | + $scopeId |
| 228 | + ); |
| 229 | + |
| 230 | + $this->reinitConfig(); |
| 231 | + } |
| 232 | + |
| 233 | + private function reinitConfig(): void |
| 234 | + { |
| 235 | + /** @var ReinitableConfigInterface $config */ |
| 236 | + $config = $this->objectManager->get(ReinitableConfigInterface::class); |
| 237 | + $config->reinit(); |
| 238 | + } |
148 | 239 | }
|
0 commit comments