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 607e5c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions codeception/acceptance/EF02ProductCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,27 @@ 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
$I->wantTo('EF0202-UC01-T04 商品詳細 構造化データ');

// 在庫ありのテスト
$I->setStock(1, 1);
ProductDetailPage::go($I, 1);
$html = $I->grabAttributeFrom('script[type="application/ld+json"]', 'innerHTML');
$json_ld = json_decode((string)$html);
$html = $I->grabMultiple('script[type="application/ld+json"]', 'innerHTML');
$json_ld = json_decode($html[0]);
$I->assertEquals($json_ld->{'@type'}, 'Product');
$I->assertEquals($json_ld->name, '彩のジェラートCUBE');
$I->assertEquals($json_ld->offers->price, 5500);
$I->assertEquals($json_ld->offers->availability, 'InStock');

// 在庫なしのテスト
$I->setStock(2, 0);
ProductDetailPage::go($I, 2);
$html = $I->grabMultiple('script[type="application/ld+json"]', 'innerHTML');
$json_ld = json_decode($html[0]);
$I->assertEquals($json_ld->name, 'チェリーアイスサンド');
$I->assertEquals($json_ld->offers->availability, 'OutOfStock');
}

public function product_商品詳細カート1(\AcceptanceTester $I)
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

0 comments on commit 607e5c5

Please sign in to comment.