Skip to content

Commit

Permalink
MAGETWO-57995: [GITHUB] Simple product videos display the thumbnail i…
Browse files Browse the repository at this point in the history
…mage rather than the embedded video player. #6360
  • Loading branch information
olysenko committed May 23, 2017
1 parent 8a22ae9 commit d8ad9f7
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ class View extends AbstractConfigureBlock
*/
private $videoContainer = 'div.fotorama-video-container';

/**
* @var string
*/
private $productVideo = '.product-video';

/**
* Threshold message selector.
*
Expand Down Expand Up @@ -647,4 +652,16 @@ public function isVideoVisible()
{
return $this->_rootElement->find($this->videoContainer)->isVisible();
}

/**
* Check definite video data is presented on product page
*
* @param string $videoData
* @return bool
*/
public function checkVideoDataPresence($videoData)
{
$dataVideoSelector = $this->productVideo . '[data-code="' . $videoData. '"]';
return $this->_rootElement->find($dataVideoSelector)->isPresent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,27 @@ public function isVisible()
{
return $this->_rootElement->find($this->optionsContext, Locator::SELECTOR_XPATH)->isVisible();
}

/**
* Select configurable product option by it index
*
* @param FixtureInterface $product
* @param string $variation
* @return void
*/
public function selectConfigurableOption(FixtureInterface $product, $variation)
{
/** @var ConfigurableProduct $product */
$attributesData = [];
$productVariations = [];
if ($product->hasData('configurable_attributes_data')) {
$attributesData = $product->getConfigurableAttributesData()['attributes_data'];
$productVariations = $product->getConfigurableAttributesData()['matrix'];
}
if (array_key_exists($variation, $productVariations)) {
$variationOption = explode(' ', $variation);
//Select option specified in variation
$this->chooseOptions($variationOption, $attributesData);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1037,5 +1037,49 @@
<item name="dataset" xsi:type="string">default</item>
</field>
</dataset>
<dataset name="configurable_with_video">
<field name="name" xsi:type="string">Test configurable product %isolation%</field>
<field name="sku" xsi:type="string">sku_test_configurable_product_%isolation%</field>
<field name="price" xsi:type="array">
<item name="value" xsi:type="string">40</item>
<item name="dataset" xsi:type="string">price_40</item>
</field>
<field name="product_has_weight" xsi:type="string">This item has weight</field>
<field name="weight" xsi:type="string">1</field>
<field name="status" xsi:type="string">Yes</field>
<field name="visibility" xsi:type="string">Catalog, Search</field>
<field name="tax_class_id" xsi:type="array">
<item name="dataset" xsi:type="string">taxable_goods</item>
</field>
<field name="url_key" xsi:type="string">configurable-product-%isolation%</field>
<field name="configurable_attributes_data" xsi:type="array">
<item name="dataset" xsi:type="string">default</item>
</field>
<field name="quantity_and_stock_status" xsi:type="array">
<item name="is_in_stock" xsi:type="string">In Stock</item>
</field>
<field name="website_ids" xsi:type="array">
<item name="0" xsi:type="array">
<item name="dataset" xsi:type="string">default</item>
</item>
</field>
<field name="attribute_set_id" xsi:type="array">
<item name="dataset" xsi:type="string">default</item>
</field>
<field name="checkout_data" xsi:type="array">
<item name="dataset" xsi:type="string">configurable_default</item>
</field>
<field name="category_ids" xsi:type="array">
<item name="dataset" xsi:type="string">default_subcategory</item>
</field>
<field name="media_gallery" xsi:type="array">
<item name="images" xsi:type="array">
<item name="0" xsi:type="array">
<item name="video_url" xsi:type="string">https://youtu.be/bpOSxM0rNPM</item>
<item name="video_title" xsi:type="string">Some title</item>
</item>
</item>
</field>
</dataset>
</repository>
</config>
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?xml version="1.0" ?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<sections>
<images-and-videos>
<class>\Magento\ProductVideo\Test\Block\Adminhtml\Product\Edit\Tab\ImagesAndVideos</class>
<selector>[data-index="block_gallery"]</selector>
<strategy>css selector</strategy>
<fields>
<position />
<media_type />
<video_provider />
<file />
<value_id />
<label />
<disabled />
<removed />
<video_url />
<video_title />
<video_description />
<video_metadata />
<role />
</fields>
</images-and-videos>
</sections>
<?xml version="1.0" ?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<sections>
<images-and-videos>
<class>\Magento\ProductVideo\Test\Block\Adminhtml\Product\Edit\Tab\ImagesAndVideos</class>
<selector>[data-index="gallery"]</selector>
<strategy>css selector</strategy>
<fields>
<position />
<media_type />
<video_provider />
<file />
<value_id />
<label />
<disabled />
<removed />
<video_url />
<video_title />
<video_description />
<video_metadata />
<role />
</fields>
</images-and-videos>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ProductVideo\Test\Constraint;

use Magento\Mtf\Client\BrowserInterface;
use Magento\Mtf\Fixture\InjectableFixture;
use Magento\Mtf\Constraint\AbstractConstraint;
use Magento\Catalog\Test\Page\Product\CatalogProductView;

/**
* Assert that video is displayed on product page.
*/
class AssertVideoConfigurableProductView extends AbstractConstraint
{
/**
* Assert that video is displayed on product page on Store front.
*
* @param BrowserInterface $browser
* @param CatalogProductView $catalogProductView
* @param InjectableFixture $product
* @param string $youtubeDataCode
* @param string $vimeoDataCode
* @param string $variation
*/
public function processAssert(
BrowserInterface $browser,
CatalogProductView $catalogProductView,
InjectableFixture $product,
$youtubeDataCode,
$vimeoDataCode,
$variation
) {
//open product page
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
// assert video and video data of configurable product is presented on page
\PHPUnit_Framework_Assert::assertTrue(
$catalogProductView->getViewBlock()->isVideoVisible(),
'Product video is not displayed on product view when it should.'
);
\PHPUnit_Framework_Assert::assertTrue(
$catalogProductView->getViewBlock()->checkVideoDataPresence($youtubeDataCode),
'Configurable product video data is not displayed on product view when it should.'
);
// select configurable product variation
$catalogProductView->getConfigurableAttributesBlock()->selectConfigurableOption($product, $variation);
// assert video and video data of simple product option is presented on page
\PHPUnit_Framework_Assert::assertTrue(
$catalogProductView->getViewBlock()->isVideoVisible(),
'Configurable product variation video is not displayed on product view when it should.'
);
\PHPUnit_Framework_Assert::assertTrue(
$catalogProductView->getViewBlock()->checkVideoDataPresence($vimeoDataCode),
'Configurable product variation video data is not displayed on product view when it should.'
);
}

/**
* Returns a string representation of the object.
*
* @return string
*/
public function toString()
{
return 'Configurable product video and it variation video are displayed on product view.';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd">
<fixture name="configurableProduct">
<field name="media_gallery" is_required="0" group="images-and-videos" source="Magento\ProductVideo\Test\Fixture\Product\MediaGallery"/>
</fixture>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ProductVideo\Test\TestCase;

use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
use Magento\Catalog\Test\Page\Adminhtml\CatalogProductNew;
use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
use Magento\Config\Test\TestStep\SetupConfigurationStep;
use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct;
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
use Magento\Mtf\TestCase\Injectable;
use Magento\Mtf\TestStep\TestStepFactory;
use Magento\Catalog\Test\Constraint\AssertProductSaveMessage;

/**
* Steps:
* 1. Go to backend.
* 2. Create configurable product with several simple product variations.
* 3. Add a video to a configurable product
* 4. Add video to simple products of that configurable product.
* 5. View that configurable product page on the frontend.
* 6. Select the product configuration to display the simple product for which the video was added.
* 7. Perform asserts.
*
* @group ProductVideo
* @ZephyrId MAGETWO-69381
*/
class ConfigurableProductVideoTest extends Injectable
{
/* tags */
const TEST_TYPE = 'acceptance_test, extended_acceptance_test';
const MVP = 'yes';
/* end tags */

/**
* Product page with a grid.
*
* @var CatalogProductIndex
*/
private $productIndex;

/**
* Page to create a product.
*
* @var CatalogProductNew
*/
private $productNew;

/**
* Product edit page.
*
* @var CatalogProductEdit
*/
private $productEdit;

/**
* Factory for creation SetupConfigurationStep.
*
* @var TestStepFactory
*/
private $testStepFactory;

/**
* Configuration data holder.
*
* @var string
*/
private $configData = null;

/**
* @param CatalogProductIndex $productIndex
* @param CatalogProductNew $productNew
* @param CatalogProductEdit $productEdit
* @param TestStepFactory $testStepFactory
*/
public function __inject(
CatalogProductIndex $productIndex,
CatalogProductNew $productNew,
CatalogProductEdit $productEdit,
TestStepFactory $testStepFactory
) {
$this->productIndex = $productIndex;
$this->productNew = $productNew;
$this->productEdit = $productEdit;
$this->testStepFactory = $testStepFactory;
}

/**
* @param CatalogProductSimple $simpleProductVideo
* @param ConfigurableProduct $product
* @param AssertProductSaveMessage $assertCreateProducts
* @param string $variation
* @param null $configData
*/
public function test(
CatalogProductSimple $simpleProductVideo,
ConfigurableProduct $product,
AssertProductSaveMessage $assertCreateProducts,
$variation,
$configData = null
) {
//Preconditions
$this->configData = $configData;
$this->testStepFactory->create(
SetupConfigurationStep::class,
['configData' => $this->configData, 'flushCache' => true]
)->run();

// Steps
$this->productIndex->open();
$this->productIndex->getGridPageActionBlock()->addProduct('configurable');
$this->productNew->getProductForm()->fill($product);
$this->productNew->getFormPageActions()->save($product);
$assertCreateProducts->processAssert($this->productEdit);

$sku = $product->getConfigurableAttributesData()['matrix'][$variation]['sku'];
$this->productIndex->open();
$this->productIndex->getProductGrid()->searchAndOpen(['sku' => $sku]);
$this->productEdit->getProductForm()->fill($simpleProductVideo);
$this->productEdit->getFormPageActions()->save();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
<testCase name="Magento\ProductVideo\Test\TestCase\ConfigurableProductVideoTest" summary="Video displaying for simple variation of configurable on product page" ticketId="MAGETWO-69381">
<variation name="ConfigurableProductVideoTestVariation1">
<data name="product/dataset" xsi:type="string">configurable_with_video</data>
<data name="simpleProductVideo/data/media_gallery/images/0/video_url" xsi:type="string">https://vimeo.com/16342611</data>
<data name="variation" xsi:type="string">attribute_key_0:option_key_0 attribute_key_1:option_key_0</data>
<data name="configData" xsi:type="string">youtube_api_key,play_if_base</data>
<data name="vimeoDataCode" xsi:type="string">16342611</data>
<data name="youtubeDataCode" xsi:type="string">bpOSxM0rNPM</data>
<constraint name="Magento\ProductVideo\Test\Constraint\AssertVideoConfigurableProductView" />
</variation>
</testCase>
</config>
Loading

0 comments on commit d8ad9f7

Please sign in to comment.