Skip to content

Commit aac1d8c

Browse files
committed
MC-39606: Create automated test for: "Save the product with "Set new as from" attribute"
1 parent 00a70ec commit aac1d8c

File tree

1 file changed

+75
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Model\Attribute\Backend;
10+
11+
use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
12+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
13+
use Magento\Catalog\Model\Product;
14+
use Magento\Eav\Model\Config;
15+
use Magento\Eav\Model\Entity\Attribute\Exception;
16+
use Magento\Framework\ObjectManagerInterface;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Test for Special Start Date attribute
22+
*
23+
* @magentoAppArea adminhtml
24+
* @magentoAppIsolation enabled
25+
*/
26+
class StartdateTest extends TestCase
27+
{
28+
/** @var ObjectManagerInterface */
29+
private $objectManager;
30+
31+
/** @var ProductInterfaceFactory */
32+
private $productFactory;
33+
34+
/** @var Startdate */
35+
private $startDate;
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
protected function setUp(): void
41+
{
42+
parent::setUp();
43+
44+
$this->objectManager = Bootstrap::getObjectManager();
45+
$this->productFactory = $this->objectManager->get(ProductInterfaceFactory::class);
46+
$this->startDate = $this->objectManager->get(Startdate::class);
47+
$attribute = $this->objectManager->get(Config::class)->getAttribute(Product::ENTITY, 'news_from_date');
48+
$attribute->setMaxValue(date('Y-m-d H:i:s', strtotime('-10 days')));
49+
$this->startDate->setAttribute($attribute);
50+
}
51+
52+
/**
53+
* @return void
54+
*/
55+
public function testBeforeSave(): void
56+
{
57+
$product = $this->productFactory->create();
58+
$product->setNewsFromDate(false);
59+
$this->startDate->beforeSave($product);
60+
$this->assertNull($product->getNewsFromDateIsFormated());
61+
}
62+
63+
/**
64+
* @return void
65+
*/
66+
public function testValidate(): void
67+
{
68+
$product = $this->productFactory->create();
69+
$product->setNewsFromDate(date('d-m-Y'));
70+
$this->expectException(Exception::class);
71+
$msg = __('Make sure the To Date is later than or the same as the From Date.');
72+
$this->expectExceptionMessage((string)$msg);
73+
$this->startDate->validate($product);
74+
}
75+
}

0 commit comments

Comments
 (0)