Skip to content

Commit

Permalink
Covered testNonExistentEntityUrlRewrite case
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshsuhagiya committed Apr 4, 2019
1 parent 273ea48 commit 43ba611
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,30 @@ public function testGetNonExistentUrlRewrite()
$this->assertEquals('PRODUCT', $response['urlResolver']['type']);
$this->assertEquals($targetPath, $response['urlResolver']['relative_url']);
}

/**
* Test for custom type which point to the invalid product/category/cms page.
*
* @magentoApiDataFixture Magento/UrlRewrite/_files/url_rewrite_not_existing_entity.php
*/
public function testNonExistentEntityUrlRewrite()
{
$urlPath = 'non-exist-entity.html';

$query = <<<QUERY
{
urlResolver(url:"{$urlPath}")
{
id
relative_url
type
}
}
QUERY;

$this->expectExceptionMessage(
"No such entity found with matching URL key: " . $urlPath
);
$this->graphQlQuery($query);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\TestFramework\Helper\Bootstrap;
use Magento\UrlRewrite\Model\UrlRewrite;

$objectManager = Bootstrap::getObjectManager();

/** @var int Product Id */
$productId = 708579;

/** @var UrlRewrite $urlRewrite */
$urlRewrite = $objectManager->create(UrlRewrite::class);
$urlRewrite->setEntityType('custom')
->setRequestPath('non-exist-entity.html')
->setTargetPath('catalog/product/view/id/' . $productId)
->setRedirectType(0)
->setStoreId(1)
->setDescription(null)
->setIsAutogenerated(0);

$urlRewrite->save();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\TestFramework\Helper\Bootstrap;
use Magento\UrlRewrite\Model\UrlRewrite;

$objectManager = Bootstrap::getObjectManager();

/** @var UrlRewrite $urlRewrite */
$urlRewrite = $objectManager->create(UrlRewrite::class);
$urlRewrite->load('non-exist-entity.html', 'request_path');
$urlRewrite->delete();

0 comments on commit 43ba611

Please sign in to comment.