public function ProductTest::testProduct in Commerce Core 8.2
@covers ::getTitle @covers ::setTitle @covers ::getCreatedTime @covers ::setCreatedTime @covers ::getStores @covers ::setStores @covers ::getStoreIds @covers ::setStoreIds @covers ::getOwner @covers ::setOwner @covers ::getOwnerId @covers ::setOwnerId
File
- modules/
product/ tests/ src/ Kernel/ Entity/ ProductTest.php, line 65
Class
- ProductTest
- Tests the Product entity.
Namespace
Drupal\Tests\commerce_product\Kernel\EntityCode
public function testProduct() {
$product = Product::create([
'type' => 'default',
]);
$product
->save();
$product
->setTitle('My title');
$this
->assertEquals('My title', $product
->getTitle());
$product
->setCreatedTime(635879700);
$this
->assertEquals(635879700, $product
->getCreatedTime());
$product
->setStores([
$this->store,
]);
$this
->assertEquals([
$this->store,
], $product
->getStores());
$this
->assertEquals([
$this->store
->id(),
], $product
->getStoreIds());
$product
->setStores([]);
$this
->assertEquals([], $product
->getStores());
$product
->setStoreIds([
$this->store
->id(),
]);
$this
->assertEquals([
$this->store,
], $product
->getStores());
$this
->assertEquals([
$this->store
->id(),
], $product
->getStoreIds());
$product
->setOwner($this->user);
$this
->assertEquals($this->user, $product
->getOwner());
$this
->assertEquals($this->user
->id(), $product
->getOwnerId());
$product
->setOwnerId(0);
$this
->assertInstanceOf(UserInterface::class, $product
->getOwner());
$this
->assertTrue($product
->getOwner()
->isAnonymous());
// Non-existent/deleted user ID.
$product
->setOwnerId(891);
$this
->assertInstanceOf(UserInterface::class, $product
->getOwner());
$this
->assertTrue($product
->getOwner()
->isAnonymous());
$this
->assertEquals(891, $product
->getOwnerId());
$product
->setOwnerId($this->user
->id());
$this
->assertEquals($this->user, $product
->getOwner());
$this
->assertEquals($this->user
->id(), $product
->getOwnerId());
$this
->assertEquals([
'store',
'url.query_args:v',
], $product
->getCacheContexts());
// Ensure that we don't store a broken reference to the product owner.
$product
->setOwnerId(900);
$this
->assertEquals(900, $product
->getOwnerId());
$product
->save();
$this
->assertEquals(0, $product
->getOwnerId());
}