Skip to content

Commit

Permalink
構造化データ テストコードの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
h.matsuo committed Mar 25, 2021
1 parent 4b65f08 commit 7d60e98
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
13 changes: 0 additions & 13 deletions codeception/acceptance/EF02ProductCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,6 @@ public function product_商品詳細サムネイル(\AcceptanceTester $I)
$I->assertRegExp('/\/upload\/save_image\/sand-2\.png$/', $img, $img.' が見つかりません');
}

/**
* @group EF0202-UC01-T04
*/
public function product_商品詳細構造化データ(\AcceptanceTester $I)
{
$I->wantTo('EF0202-UC01-T04 商品詳細 構造化データ'); // todo

ProductDetailPage::go($I, 1);
$html = $I->grabAttributeFrom('script[type="application/ld+json"]', 'innerHTML');
$json_ld = json_decode((string)$html);
$I->assertEquals($json_ld->name, '彩のジェラートCUBE');
}

public function product_商品詳細カート1(\AcceptanceTester $I)
{
$I->wantTo('EF0202-UC02-T01 商品詳細 カート 注文数<販売制限数<在庫数の注文');
Expand Down
4 changes: 2 additions & 2 deletions src/Eccube/Resource/template/default/Product/detail.twig
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ file that was distributed with this source code.
"{{ url('homepage') }}{{ asset(no_image_product, 'save_image') }}"
{% endfor %}
],
"description": "{{ Product.description_list | default(Product.description_detail) | striptags | replace({"\n": '', "\r": ''}, '') }}",
"description": "{{ Product.description_list | default(Product.description_detail) | striptags | replace({'\n': '', '\r': ''}) }}",
"sku": "{{ Product.code_min }}",
"offers": {
"@type": "Offer",
"url": "{{ url('product_detail', {'id': Product.id}) }}",
"priceCurrency": "JPY",
"priceCurrency": "{{ eccube_config.currency }}",
"price": {{ Product.getPrice02IncTaxMin }},
"availability": "{{ Product.stock_find ? "InStock" : "OutOfStock" }}"
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Eccube/Tests/Web/ProductControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,31 @@ public function testProductFavoriteAddThroughLogin()
$html = $crawler->filter('div.ec-productRole__profile')->html();
$this->assertContains('お気に入りに追加済です', $html);
}

/**
* 商品詳細ページの構造化データ
*/
public function testProductStructureData()
{
$crawler = $this->client->request('GET', $this->generateUrl('product_detail', ['id' => 2]));
$json = json_decode(html_entity_decode($crawler->filter('script[type="application/ld+json"]')->html()));
$this->assertEquals('Product', $json->{'@type'});
$this->assertEquals('チェリーアイスサンド', $json->name);
$this->assertEquals(3080, $json->offers->price);
$this->assertEquals('InStock', $json->offers->availability);

// 在庫なし商品のテスト
$Product = $this->createProduct('Product no stock', 1);
$ProductClass = $Product->getProductClasses()->first();
$ProductClass->setStockUnlimited(false);
$ProductClass->setStock(0);
$ProductStock = $ProductClass->getProductStock();
$ProductStock->setStock(0);
$this->entityManager->flush();

$crawler = $this->client->request('GET', $this->generateUrl('product_detail', ['id' => $Product->getId()]));
$json = json_decode(html_entity_decode($crawler->filter('script[type="application/ld+json"]')->html()));
$this->assertEquals('Product no stock', $json->name);
$this->assertEquals('OutOfStock', $json->offers->availability);
}
}

0 comments on commit 7d60e98

Please sign in to comment.