public function ProductTest::testCanonicalVariationLink in Commerce Core 8.2
Tests variation's canonical URL.
File
- modules/
product/ tests/ src/ Kernel/ Entity/ ProductTest.php, line 190
Class
- ProductTest
- Tests the Product entity.
Namespace
Drupal\Tests\commerce_product\Kernel\EntityCode
public function testCanonicalVariationLink() {
$variation1 = ProductVariation::create([
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
'title' => $this
->randomString(),
'status' => 0,
]);
$variation1
->save();
$product = Product::create([
'type' => 'default',
'title' => 'My product',
'variations' => [
$variation1,
],
]);
$product
->save();
$product_url = $product
->toUrl()
->toString();
$variation_url = $variation1
->toUrl()
->toString();
$this
->assertEquals($product_url . '?v=' . $variation1
->id(), $variation_url);
}