Skip to content

Commit cec15d8

Browse files
committed
MAGETWO-59503: URL rewrite not created when URL key is changed for a product
- extens test
1 parent 1ab7661 commit cec15d8

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ public function setUp()
8484
$this->product = $this->getMockBuilder(Product::class)
8585
->disableOriginalConstructor()
8686
->setMethods([
87-
'getProductCategories',
88-
'dataHasChangedFor',
89-
'getVisibility'
87+
'getProductCategories'
9088
])
9189
->getMock();
9290

@@ -98,24 +96,58 @@ public function setUp()
9896

9997
}
10098

101-
public function testVisibility()
99+
/**
100+
* @dataProvider visibilityProvider
101+
* @param integer $before
102+
* @param integer $after
103+
*/
104+
public function testVisibility($before, $after)
102105
{
106+
$this->product->setOrigData('visibility', $before);
107+
$this->product->setData('visibility', $after);
108+
103109
$this->productUrlRewriteGenerator->expects(static::once())
104110
->method('generate')
105111
->with($this->product)
106-
->willReturn([]);
107-
$this->urlPersist->expects(static::atLeastOnce())
112+
->willReturn(['test']);
113+
$this->urlPersist->expects(static::once())
108114
->method('replace')
109-
->with([]);
110-
$this->product->expects(static::atLeastOnce())
111-
->method('getVisibility')
112-
->willReturn(Visibility::VISIBILITY_IN_CATALOG);
113-
$this->product->expects(static::atLeastOnce())
114-
->method('dataHasChangedFor')
115-
->willReturnMap([
116-
['visibility', true],
117-
]);
115+
->with(['test']);
118116

119117
$this->productProcessUrlRewriteSavingObserver->execute($this->observer);
120118
}
119+
120+
public function visibilityProvider()
121+
{
122+
return [
123+
['origData' => Visibility::VISIBILITY_NOT_VISIBLE, 'data' => Visibility::VISIBILITY_IN_CATALOG],
124+
['origData' => null, 'data' => Visibility::VISIBILITY_IN_CATALOG],
125+
['origData' => Visibility::VISIBILITY_BOTH, 'data' => Visibility::VISIBILITY_IN_SEARCH],
126+
];
127+
}
128+
129+
/**
130+
* @dataProvider notVisibilityProvider
131+
* @param integer $before
132+
* @param integer $after
133+
*/
134+
public function testNotVisibility($before, $after)
135+
{
136+
$this->product->setOrigData('visibility', $before);
137+
$this->product->setData('visibility', $after);
138+
139+
$this->productUrlRewriteGenerator->expects(static::never())->method('generate');
140+
$this->urlPersist->expects(static::never())->method('replace');
141+
142+
$this->productProcessUrlRewriteSavingObserver->execute($this->observer);
143+
}
144+
145+
public function notVisibilityProvider()
146+
{
147+
return [
148+
['origData' => Visibility::VISIBILITY_IN_SEARCH, 'data' => Visibility::VISIBILITY_IN_SEARCH],
149+
['origData' => Visibility::VISIBILITY_IN_CATALOG, 'data' => Visibility::VISIBILITY_NOT_VISIBLE],
150+
['origData' => null, 'data' => Visibility::VISIBILITY_NOT_VISIBLE],
151+
];
152+
}
121153
}

0 commit comments

Comments
 (0)