Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateCmsPageRewriteEntityTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Backend\Test\Page\Adminhtml\StoreDelete;
10 use Magento\Backend\Test\Page\Adminhtml\StoreIndex;
11 use Magento\Backend\Test\Page\Adminhtml\StoreNew;
13 use Magento\UrlRewrite\Test\Page\Adminhtml\UrlRewriteEdit;
14 use Magento\UrlRewrite\Test\Page\Adminhtml\UrlRewriteIndex;
15 use Magento\Mtf\TestCase\Injectable;
16 
34 class UpdateCmsPageRewriteEntityTest extends Injectable
35 {
36  /* tags */
37  const MVP = 'yes';
38  const SEVERITY = 'S2';
39  /* end tags */
40 
46  protected $urlRewriteIndex;
47 
53  protected $urlRewriteEdit;
54 
60  protected $storeIndex;
61 
67  protected $storeNew;
68 
74  protected $storeDelete;
75 
81  protected $storeName;
82 
88  protected $skippedStores = [
89  'Main Website/Main Website Store/Default Store View',
90  ];
91 
102  public function __inject(
103  UrlRewriteIndex $urlRewriteIndex,
104  UrlRewriteEdit $urlRewriteEdit,
105  StoreIndex $storeIndex,
106  StoreNew $storeNew,
107  StoreDelete $storeDelete
108  ) {
109  $this->urlRewriteIndex = $urlRewriteIndex;
110  $this->urlRewriteEdit = $urlRewriteEdit;
111  $this->storeIndex = $storeIndex;
112  $this->storeNew = $storeNew;
113  $this->storeDelete = $storeDelete;
114  }
115 
123  public function test(UrlRewrite $urlRewrite, UrlRewrite $cmsPageRewrite)
124  {
125  // Preconditions
126  $cmsPageRewrite->persist();
127 
128  // Steps
129  $this->urlRewriteIndex->open();
130  $this->storeName = $urlRewrite->getStoreId();
131  $filter = ['request_path' => $cmsPageRewrite->getRequestPath()];
132  $this->urlRewriteIndex->getUrlRedirectGrid()->searchAndOpen($filter);
133  $this->urlRewriteEdit->getFormBlock()->fill($urlRewrite);
134  $this->urlRewriteEdit->getPageMainActions()->save();
135 
136  return ['cmsPage' => $cmsPageRewrite->getDataFieldConfig('target_path')['source']->getEntity()];
137  }
138 
144  public function tearDown()
145  {
146  if (in_array($this->storeName, $this->skippedStores)) {
147  return;
148  }
149  $storeName = explode("/", $this->storeName);
150  $filter['store_title'] = end($storeName);
151  $this->storeIndex->open();
152  $this->storeIndex->getStoreGrid()->searchAndOpen($filter);
153  $this->storeNew->getFormPageActions()->delete();
154  $this->storeDelete->getStoreForm()->fillForm(['create_backup' => 'No']);
155  $this->storeDelete->getFormPageActions()->delete();
156  }
157 }
test(UrlRewrite $urlRewrite, UrlRewrite $cmsPageRewrite)
__inject(UrlRewriteIndex $urlRewriteIndex, UrlRewriteEdit $urlRewriteEdit, StoreIndex $storeIndex, StoreNew $storeNew, StoreDelete $storeDelete)