|
7 | 7 |
|
8 | 8 | namespace Magento\ProductAlert\Model\Mailing;
|
9 | 9 |
|
| 10 | +use Magento\Catalog\Api\ProductRepositoryInterface; |
| 11 | +use Magento\Catalog\Model\ProductFactory; |
| 12 | +use Magento\Catalog\Model\ResourceModel\Product as ProductResourceModel; |
10 | 13 | use Magento\Customer\Api\AccountManagementInterface;
|
11 | 14 | use Magento\Customer\Model\Session;
|
12 | 15 | use Magento\Framework\App\Area;
|
|
16 | 19 | use Magento\Framework\Phrase\Renderer\Translate as PhraseRendererTranslate;
|
17 | 20 | use Magento\Framework\Phrase\RendererInterface;
|
18 | 21 | use Magento\Framework\Translate;
|
| 22 | +use Magento\Store\Model\Store; |
19 | 23 | use Magento\Store\Model\StoreRepository;
|
20 | 24 | use Magento\TestFramework\Helper\Bootstrap;
|
21 | 25 | use Magento\TestFramework\Mail\Template\TransportBuilderMock;
|
22 | 26 | use Magento\TestFramework\ObjectManager;
|
23 | 27 | use PHPUnit\Framework\TestCase;
|
24 | 28 |
|
25 | 29 | /**
|
26 |
| -* Test for Product Alert observer |
27 |
| -* |
28 |
| -* @magentoAppIsolation enabled |
29 |
| -* @magentoAppArea frontend |
30 |
| -*/ |
| 30 | + * Test for Product Alert observer |
| 31 | + * |
| 32 | + * @magentoAppIsolation enabled |
| 33 | + * @magentoAppArea frontend |
| 34 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 35 | + */ |
31 | 36 | class AlertProcessorTest extends TestCase
|
32 | 37 | {
|
33 | 38 | /**
|
@@ -127,6 +132,37 @@ public function testProcessPortuguese()
|
127 | 132 | $this->assertStringContainsString(substr($expectedText, 0, 50), $messageContent);
|
128 | 133 | }
|
129 | 134 |
|
| 135 | + /** |
| 136 | + * @magentoConfigFixture current_store catalog/productalert/allow_price 1 |
| 137 | + * @magentoDataFixture Magento/ProductAlert/_files/product_alert.php |
| 138 | + */ |
| 139 | + public function testCustomerShouldGetEmailForEveryProductPriceDrop(): void |
| 140 | + { |
| 141 | + $this->processAlerts(); |
| 142 | + |
| 143 | + $this->assertStringContainsString( |
| 144 | + '$10.00', |
| 145 | + $this->transportBuilder->getSentMessage()->getBody()->getParts()[0]->getRawContent() |
| 146 | + ); |
| 147 | + |
| 148 | + // Intentional: update product without using ProductRepository |
| 149 | + // to prevent changes from being cached on application level |
| 150 | + $product = $this->objectManager->get(ProductFactory::class)->create(); |
| 151 | + $productRepository = $this->objectManager->get(ProductRepositoryInterface::class); |
| 152 | + $productResource = $this->objectManager->get(ProductResourceModel::class); |
| 153 | + $product->setStoreId(Store::DEFAULT_STORE_ID); |
| 154 | + $productResource->load($product, $productRepository->get('simple')->getId()); |
| 155 | + $product->setPrice(5); |
| 156 | + $productResource->save($product); |
| 157 | + |
| 158 | + $this->processAlerts(); |
| 159 | + |
| 160 | + $this->assertStringContainsString( |
| 161 | + '$5.00', |
| 162 | + $this->transportBuilder->getSentMessage()->getBody()->getParts()[0]->getRawContent() |
| 163 | + ); |
| 164 | + } |
| 165 | + |
130 | 166 | /**
|
131 | 167 | * Process price alerts
|
132 | 168 | */
|
|
0 commit comments