Skip to content

Commit ef44a56

Browse files
committed
MAGETWO-66480: [GITHUB] URL key for specified store already exists #6671
- functional tests
1 parent 7b3e705 commit ef44a56

11 files changed

+358
-31
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function execute()
113113
}
114114
return $resultRedirect->setPath('*/*/');
115115
} catch (LocalizedException $e) {
116-
$this->messageManager->addExceptionMessage($e);
116+
$this->messageManager->addExceptionMessage($e->getPrevious() ?:$e);
117117
} catch (\Exception $e) {
118118
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the page.'));
119119
}

app/code/Magento/Cms/Model/PageRepository.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ public function save(\Magento\Cms\Api\Data\PageInterface $page)
117117
try {
118118
$this->resource->save($page);
119119
} catch (\Exception $exception) {
120-
throw new CouldNotSaveException(__(
121-
'Could not save the page: %1',
122-
$exception->getMessage()
123-
));
120+
throw new CouldNotSaveException(
121+
__('Could not save the page: %1', $exception->getMessage()),
122+
$exception
123+
);
124124
}
125125
return $page;
126126
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogUrlRewrite\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
use Magento\Catalog\Test\Fixture\Category;
12+
13+
/**
14+
* Class AssertCategoryUrlDuplicateErrorMessage
15+
*/
16+
class AssertCategoryUrlDuplicateErrorMessage extends AbstractConstraint
17+
{
18+
/**
19+
* Text title of the error message to be checked.
20+
*/
21+
const ERROR_MESSAGE_TITLE = 'The value specified in the URL Key field would generate a URL that already exists.';
22+
23+
/**
24+
* Assert that success message is displayed after category save.
25+
*
26+
* @param CatalogCategoryEdit $productPage
27+
* @param Category $category
28+
* @return void
29+
*/
30+
public function processAssert(
31+
CatalogCategoryEdit $productPage,
32+
Category $category
33+
) {
34+
$actualMessage = $productPage->getMessagesBlock()->getErrorMessage();
35+
\PHPUnit_Framework_Assert::assertContains(
36+
self::ERROR_MESSAGE_TITLE,
37+
$actualMessage,
38+
'Wrong error message is displayed.'
39+
. "\nExpected: " . self::ERROR_MESSAGE_TITLE
40+
. "\nActual:\n" . $actualMessage
41+
);
42+
43+
\PHPUnit_Framework_Assert::assertContains(
44+
$category->getUrlKey(),
45+
$actualMessage,
46+
'Category url is not present on error message.'
47+
. "\nExpected: " . self::ERROR_MESSAGE_TITLE
48+
. "\nActual:\n" . $actualMessage
49+
);
50+
}
51+
52+
/**
53+
* Returns a string representation of the object
54+
*
55+
* @return string
56+
*/
57+
public function toString()
58+
{
59+
return 'Category url duplication error on save message is present.';
60+
}
61+
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
1313

1414
/**
15-
* Class AssertUrlDuplicateErrorMessage
15+
* Class AssertProductUrlDuplicateErrorMessage
1616
*/
17-
class AssertUrlDuplicateErrorMessage extends AbstractConstraint
17+
class AssertProductUrlDuplicateErrorMessage extends AbstractConstraint
1818
{
1919
/**
2020
* Text title of the error message to be checked.
@@ -25,6 +25,8 @@ class AssertUrlDuplicateErrorMessage extends AbstractConstraint
2525
* Assert that success message is displayed after product save.
2626
*
2727
* @param CatalogProductEdit $productPage
28+
* @param CatalogProductSimple $product
29+
* @param Category $category
2830
* @return void
2931
*/
3032
public function processAssert(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogUrlRewrite\Test\TestCase;
8+
9+
use Magento\Catalog\Test\Fixture\Category;
10+
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit;
11+
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryIndex;
12+
use Magento\Mtf\TestCase\Injectable;
13+
14+
/**
15+
* Test Creation for CreateCategoryEntity
16+
*
17+
* Test Flow:
18+
* 1. Login as admin
19+
* 2. Navigate to the Products>Inventory>Categories
20+
* 3. Click on 'Add Category' button
21+
* 4. Fill out all data according to data set
22+
* 5. Save category
23+
* 6. Verify created category
24+
* 7. Navigate to the Products>Inventory>Categories
25+
* 8. Click on 'Add Category' button
26+
* 9. Fill out all data according to the same data set
27+
* 10. Save category
28+
* 11. Verify that a friendly url exists error message is displayed
29+
*
30+
* @group Category_Management
31+
* @ZephyrId MAGETWO-70307
32+
*/
33+
class CreateDuplicateUrlCategoryEntityTest extends Injectable
34+
{
35+
/* tags */
36+
const MVP = 'yes';
37+
const TEST_TYPE = 'acceptance_test, extended_acceptance_test';
38+
/* end tags */
39+
40+
/**
41+
* Catalog category index page
42+
*
43+
* @var CatalogCategoryIndex
44+
*/
45+
protected $catalogCategoryIndex;
46+
47+
/**
48+
* Catalog category edit page
49+
*
50+
* @var CatalogCategoryEdit
51+
*/
52+
protected $catalogCategoryEdit;
53+
54+
/**
55+
* Inject pages
56+
*
57+
* @param CatalogCategoryIndex $catalogCategoryIndex
58+
* @param CatalogCategoryEdit $catalogCategoryEdit
59+
* @return void
60+
*/
61+
public function __inject(CatalogCategoryIndex $catalogCategoryIndex, CatalogCategoryEdit $catalogCategoryEdit)
62+
{
63+
$this->catalogCategoryIndex = $catalogCategoryIndex;
64+
$this->catalogCategoryEdit = $catalogCategoryEdit;
65+
}
66+
67+
/**
68+
* Create category
69+
*
70+
* @param Category $category
71+
* @param string $addCategory
72+
* @return array
73+
*/
74+
public function test(Category $category, $addCategory)
75+
{
76+
for ($index = 0; $index < 2; $index++) {
77+
// Duplicate category
78+
$this->catalogCategoryIndex->open();
79+
$this->catalogCategoryIndex->getTreeCategories()->selectCategory($category, false);
80+
$this->catalogCategoryIndex->getTreeCategories()->$addCategory();
81+
$this->catalogCategoryEdit->getEditForm()->fill($category);
82+
$this->catalogCategoryEdit->getFormPageActions()->save();
83+
}
84+
85+
return ['category' => $category];
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\CatalogUrlRewrite\Test\TestCase\CreateDuplicateUrlCategoryEntityTest" summary="Create Category from Category Page" ticketId="MAGETWO-70307">
10+
<variation name="CreateDuplicateUrlCategoryEntityTestVariation1_Subcategory_RequiredFields" summary="Create Duplicate urls categories from Category page with Required Fields Only and assert error message">
11+
<data name="addCategory" xsi:type="string">addSubcategory</data>
12+
<data name="category/data/parent_id/dataset" xsi:type="string">default_category</data>
13+
<data name="category/data/is_active" xsi:type="string">Yes</data>
14+
<data name="category/data/include_in_menu" xsi:type="string">Yes</data>
15+
<data name="category/data/name" xsi:type="string">Subcategory%isolation%</data>
16+
<data name="category/data/url_key" xsi:type="string">subcategory-%isolation%</data>
17+
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
18+
<constraint name="Magento\CatalogUrlRewrite\Test\Constraint\AssertCategoryUrlDuplicateErrorMessage" />
19+
</variation>
20+
</testCase>
21+
</config>
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @group Products
2929
* @ZephyrId MAGETWO-69427
3030
*/
31-
class CreateDuplicateProductEntityTest extends Injectable
31+
class CreateDuplicateUrlProductEntity extends Injectable
3232
{
3333
/* tags */
3434
const TEST_TYPE = 'acceptance_test, extended_acceptance_test';
@@ -40,7 +40,7 @@ class CreateDuplicateProductEntityTest extends Injectable
4040
*
4141
* @var string
4242
*/
43-
protected $configData;
43+
private $configData;
4444

4545
/**
4646
* Should cache be flushed
@@ -92,17 +92,13 @@ public function testCreate(
9292
['configData' => $this->configData, 'flushCache' => $this->flushCache]
9393
)->run();
9494

95-
// Steps for simple product
96-
$productGrid->open();
97-
$productGrid->getGridPageActionBlock()->addProduct('simple');
98-
$newProductPage->getProductForm()->fill($product, null, $category);
99-
$newProductPage->getFormPageActions()->save();
100-
101-
// Steps for duplicate url product
102-
$productGrid->open();
103-
$productGrid->getGridPageActionBlock()->addProduct('simple');
104-
$newProductPage->getProductForm()->fill($product, null, $category);
105-
$newProductPage->getFormPageActions()->save();
95+
for ($index = 0; $index < 2; $index++) {
96+
// Duplicate product
97+
$productGrid->open();
98+
$productGrid->getGridPageActionBlock()->addProduct('simple');
99+
$newProductPage->getProductForm()->fill($product, null, $category);
100+
$newProductPage->getFormPageActions()->save();
101+
}
106102

107103
return ['product' => $product];
108104
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/variations.xsd">
9-
<testCase name="Magento\Catalog\Test\TestCase\Product\CreateSimpleProductEntityTest" summary="Create Simple Product" ticketId="MAGETWO-23414">
10-
<variation name="CreateDuplicateUrlProductEntityTestVariation1" summary="Create Duplicate Url Product" ticketId="MAGETWO-69427">
9+
<testCase name="Magento\CatalogUrlRewrite\Test\TestCase\CreateDuplicateUrlProductEntity" summary="Create Simple Product" ticketId="MAGETWO-69427">
10+
<variation name="CreateDuplicateUrlProductEntityTestVariation1" summary="Create Duplicate Url Product">
11+
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
1112
<data name="product/data/url_key" xsi:type="string">simple-product-%isolation%</data>
1213
<data name="product/data/name" xsi:type="string">Simple Product %isolation%</data>
1314
<data name="product/data/sku" xsi:type="string">simple_sku_%isolation%</data>
1415
<data name="product/data/price/value" xsi:type="string">10000</data>
1516
<data name="product/data/weight" xsi:type="string">50</data>
1617
<data name="product/data/quantity_and_stock_status/qty" xsi:type="string">657</data>
17-
<constraint name="Magento\CatalogUrlRewrite\Test\Constraint\AssertUrlDuplicateErrorMessage" />
18+
<constraint name="Magento\CatalogUrlRewrite\Test\Constraint\AssertProductUrlDuplicateErrorMessage" />
1819
</variation>
1920
</testCase>
2021
</config>

dev/tests/functional/tests/app/Magento/Cms/Test/Constraint/AssertCmsPageDuplicateErrorMessage.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,43 @@
88

99
use Magento\Cms\Test\Page\Adminhtml\CmsPageIndex;
1010
use Magento\Mtf\Constraint\AbstractConstraint;
11+
use Magento\Cms\Test\Fixture\CmsPage;
1112

1213
/**
1314
* Verify that page has not been created.
1415
*/
1516
class AssertCmsPageDuplicateErrorMessage extends AbstractConstraint
1617
{
17-
const ERROR_SAVE_MESSAGE = 'A page URL key for specified store already exists.';
18+
/**
19+
* Text title of the error message to be checked.
20+
*/
21+
const ERROR_MESSAGE_TITLE = 'The value specified in the URL Key field would generate a URL that already exists.';
1822

1923
/**
2024
* Verify that page has not been created.
2125
*
2226
* @param CmsPageIndex $cmsIndex
27+
* @param CmsPage $cmsPage
2328
* @return void
2429
*/
25-
public function processAssert(CmsPageIndex $cmsIndex)
30+
public function processAssert(CmsPageIndex $cmsIndex, CmsPage $cmsPage)
2631
{
27-
$message = $cmsIndex->getMessagesBlock()->getErrorMessage();
28-
\PHPUnit_Framework_Assert::assertEquals(
29-
self::ERROR_SAVE_MESSAGE,
30-
$message,
32+
$actualMessage = $cmsIndex->getMessagesBlock()->getErrorMessage();
33+
34+
\PHPUnit_Framework_Assert::assertContains(
35+
self::ERROR_MESSAGE_TITLE,
36+
$actualMessage,
3137
'Wrong error message is displayed.'
32-
. "\nExpected: " . self::ERROR_SAVE_MESSAGE
33-
. "\nActual: " . $message
38+
. "\nExpected: " . self::ERROR_MESSAGE_TITLE
39+
. "\nActual:\n" . $actualMessage
40+
);
41+
42+
\PHPUnit_Framework_Assert::assertContains(
43+
$cmsPage->getIdentifier(),
44+
$actualMessage,
45+
'CMS page url is not present on error message.'
46+
. "\nExpected: " . self::ERROR_MESSAGE_TITLE
47+
. "\nActual:\n" . $actualMessage
3448
);
3549
}
3650

0 commit comments

Comments
 (0)