Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…magento2ce into MAGETWO-75935
  • Loading branch information
AVoskoboinikov committed Sep 29, 2017
2 parents e0d572c + 9c14af7 commit 3bbb6b3
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -22,10 +23,16 @@ class DevTestsRunCommand extends Command
*/
const INPUT_ARG_TYPE = 'type';

/**
* PHPUnit arguments parameter
*/
const INPUT_OPT_COMMAND_ARGUMENTS = 'arguments';
const INPUT_OPT_COMMAND_ARGUMENTS_SHORT = 'c';

/**
* command name
*/
const COMMAND_NAME = 'dev:tests:run';
const COMMAND_NAME = 'dev:tests:run';

/**
* Maps types (from user input) to phpunit test names
Expand Down Expand Up @@ -56,6 +63,13 @@ protected function configure()
'Type of test to run. Available types: ' . implode(', ', array_keys($this->types)),
'default'
);
$this->addOption(
self::INPUT_OPT_COMMAND_ARGUMENTS,
self::INPUT_OPT_COMMAND_ARGUMENTS_SHORT,
InputOption::VALUE_REQUIRED,
'Additional arguments for PHPUnit. Example: "-c\'--filter=MyTest\'" (no spaces)',
''
);

parent::configure();
}
Expand Down Expand Up @@ -87,6 +101,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$dirName = realpath(BP . '/dev/tests/' . $dir);
chdir($dirName);
$command = PHP_BINARY . ' ' . BP . '/' . $vendorDir . '/phpunit/phpunit/phpunit ' . $options;
if ($commandArguments = $input->getOption(self::INPUT_OPT_COMMAND_ARGUMENTS)) {
$command .= ' ' . $commandArguments;
}
$message = $dirName . '> ' . $command;
$output->writeln(['', str_pad("---- {$message} ", 70, '-'), '']);
passthru($command, $returnVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@ public function testExecuteBadType()
$commandTester->execute([DevTestsRunCommand::INPUT_ARG_TYPE => 'bad']);
$this->assertContains('Invalid type: "bad"', $commandTester->getDisplay());
}

public function testPassArgumentsToPHPUnit()
{
$commandTester = new CommandTester($this->command);
$commandTester->execute(
[
DevTestsRunCommand::INPUT_ARG_TYPE => 'unit',
'-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites',
]
);
$this->assertContains(
'phpunit --list-suites',
$commandTester->getDisplay(),
'Parameters should be passed to PHPUnit'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testPrepareDataSource()
{
$itemName = 'itemName';
$oldItemValue = "itemValue\n";
$newItemValue = 'itemValue<br/>';
$newItemValue = "itemValue<br />\n";
$dataSource = [
'data' => [
'items' => [
Expand All @@ -57,7 +57,7 @@ public function testPrepareDataSource()
];

$this->model->setData('name', $itemName);
$this->escaper->expects($this->once())->method('escapeHtml')->with($newItemValue)->willReturnArgument(0);
$this->escaper->expects($this->any())->method('escapeHtml')->with($oldItemValue)->willReturnArgument(0);
$dataSource = $this->model->prepareDataSource($dataSource);
$this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$item[$this->getData('name')] = $this->escaper->escapeHtml(
str_replace("\n", '<br/>', $item[$this->getData('name')])
);
$item[$this->getData('name')] = nl2br($this->escaper->escapeHtml($item[$this->getData('name')]));
}
}

Expand Down
30 changes: 15 additions & 15 deletions app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@
<item name="total" xsi:type="string" translate="true">Row Total</item>
</argument>
</arguments>
<block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" template="Magento_Sales::order/view/items/renderer/default.phtml">
<arguments>
<argument name="columns" xsi:type="array">
<item name="product" xsi:type="string" translate="false">col-product</item>
<item name="status" xsi:type="string" translate="false">col-status</item>
<item name="price-original" xsi:type="string" translate="false">col-price-original</item>
<item name="price" xsi:type="string" translate="false">col-price</item>
<item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
<item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
<item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
<item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
<item name="discont" xsi:type="string" translate="false">col-discont</item>
<item name="total" xsi:type="string" translate="false">col-total</item>
</argument>
</arguments>
<block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" name="default_order_items_renderer" template="Magento_Sales::order/view/items/renderer/default.phtml">
<arguments>
<argument name="columns" xsi:type="array">
<item name="product" xsi:type="string" translate="false">col-product</item>
<item name="status" xsi:type="string" translate="false">col-status</item>
<item name="price-original" xsi:type="string" translate="false">col-price-original</item>
<item name="price" xsi:type="string" translate="false">col-price</item>
<item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
<item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
<item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
<item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
<item name="discont" xsi:type="string" translate="false">col-discont</item>
<item name="total" xsi:type="string" translate="false">col-total</item>
</argument>
</arguments>
</block>
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
.widget.block {
.lib-css(margin, @indent__base 0);
}
.links .widget.block { margin: 0; }
}

.no-display:extend(.abs-no-display all) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,10 @@ public function testStartActionCustomerToQuote()
/**
* Test return action with configurable product.
*
* #magentoDataFixture Magento/Paypal/_files/quote_express_configurable.php skipped due to MAGETWO-75517
* @magentoDataFixture Magento/Paypal/_files/quote_express_configurable.php
*/
public function testReturnAction()
{

$this->markTestSkipped('Test skipped due to MAGETWO-75517');
$quote = $this->_objectManager->create(Quote::class);
$quote->load('test_cart_with_configurable', 'reserved_order_id');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

$requestInfo = new \Magento\Framework\DataObject(
[
'product' => 1,
'selected_configurable_option' => 1,
'qty' => 100,
'product' => 2,
'selected_configurable_option' => 2,
'qty' => 1,
'super_attribute' => [
$attribute->getId() => $option->getId()
]
Expand Down
4 changes: 4 additions & 0 deletions dev/tests/unit/framework/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
error_reporting(E_ALL);
ini_set('display_errors', 1);

/* For data consistency between displaying (printing) and serialization a float number */
ini_set('precision', 14);
ini_set('serialize_precision', 14);

/**
* Set custom error handler
*/
Expand Down
64 changes: 59 additions & 5 deletions lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,22 @@ public function __construct(FrontendCacheInterface $cache, DbVersionInfo $dbVers
public function beforeDispatch(FrontController $subject, RequestInterface $request)
{
if (!$this->cache->load('db_is_up_to_date')) {
$errors = $this->dbVersionInfo->getDbVersionErrors();

if ($errors) {
list($versionTooLowErrors, $versionTooHighErrors) = array_values($this->getGroupedDbVersionErrors());
if ($versionTooHighErrors) {
$message = 'Please update your modules: '
. "Run \"composer install\" from the Magento root directory.\n"
. "The following modules are outdated:\n%1";
throw new LocalizedException(
new Phrase($message, [implode("\n", $this->formatVersionTooHighErrors($versionTooHighErrors))])
);
} elseif ($versionTooLowErrors) {
$message = 'Please upgrade your database: '
. "Run \"bin/magento setup:upgrade\" from the Magento root directory.\n"
. "The following modules are outdated:\n%1";

throw new LocalizedException(new Phrase($message, [implode("\n", $this->formatErrors($errors))]));
throw new LocalizedException(
new Phrase($message, [implode("\n", $this->formatVersionTooLowErrors($versionTooLowErrors))])
);
} else {
$this->cache->save('true', 'db_is_up_to_date');
}
Expand All @@ -70,7 +78,7 @@ public function beforeDispatch(FrontController $subject, RequestInterface $reque
* @param array $errorsData array of error data from getOutOfDateDbErrors
* @return array Messages that can be used to log the error
*/
private function formatErrors($errorsData)
private function formatVersionTooLowErrors($errorsData)
{
$formattedErrors = [];

Expand All @@ -82,4 +90,50 @@ private function formatErrors($errorsData)

return $formattedErrors;
}

/**
* Format each error in the error data from getOutOfDataDbErrors into a single message
*
* @param array $errorsData array of error data from getOutOfDateDbErrors
* @return array Messages that can be used to log the error
*/
private function formatVersionTooHighErrors($errorsData)
{
$formattedErrors = [];

foreach ($errorsData as $error) {
$formattedErrors[] = $error[DbVersionInfo::KEY_MODULE] . ' db ' . $error[DbVersionInfo::KEY_TYPE]
. ' version: defined in codebase - ' . $error[DbVersionInfo::KEY_REQUIRED]
. ', currently installed - ' . $error[DbVersionInfo::KEY_CURRENT];
}

return $formattedErrors;
}

/**
* Return DB version errors grouped by 'version_too_low' and 'version_too_high'
*
* @return mixed
*/
private function getGroupedDbVersionErrors()
{
$allDbVersionErrors = $this->dbVersionInfo->getDbVersionErrors();
return array_reduce(
(array)$allDbVersionErrors,
function ($carry, $item) {
if ($item[DbVersionInfo::KEY_CURRENT] === 'none'
|| $item[DbVersionInfo::KEY_CURRENT] < $item[DbVersionInfo::KEY_REQUIRED]
) {
$carry['version_too_low'][] = $item;
} else {
$carry['version_too_high'][] = $item;
}
return $carry;
},
[
'version_too_low' => [],
'version_too_high' => [],
]
);
}
}
6 changes: 6 additions & 0 deletions lib/internal/Magento/Framework/Stdlib/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public function isEmptyDate($date)
* @param int $time
* @return string The given time in given format
*
* @deprecated
* @see Use Intl library for datetime handling: http://php.net/manual/en/book.intl.php
*
* @codeCoverageIgnore
*/
public function gmDate($format, $time)
Expand All @@ -92,6 +95,9 @@ public function gmDate($format, $time)
* @param string $timeStr
* @return int
*
* @deprecated
* @see Use Intl library for datetime handling: http://php.net/manual/en/book.intl.php
*
* @codeCoverageIgnore
*/
public function strToTime($timeStr)
Expand Down
Loading

0 comments on commit 3bbb6b3

Please sign in to comment.