Skip to content

Commit e03cea5

Browse files
author
Olexandr Lysenko
committed
Merge branch 'MAGETWO-58479' into bugfixes
2 parents 60b8c5a + adac7ec commit e03cea5

File tree

4 files changed

+128
-32
lines changed

4 files changed

+128
-32
lines changed

dev/tests/integration/testsuite/Magento/Cms/Model/PageTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Cms\Model;
77

8+
use Magento\Cms\Api\PageRepositoryInterface;
9+
810
/**
911
* @magentoAppArea adminhtml
1012
*/
@@ -44,6 +46,22 @@ public function testGenerateIdentifierFromTitle($data, $expectedIdentifier)
4446
$this->assertEquals($expectedIdentifier, $page->getIdentifier());
4547
}
4648

49+
/**
50+
* @magentoDbIsolation enabled
51+
*/
52+
public function testUpdateTime()
53+
{
54+
$updateTime = '2016-09-01 00:00:00';
55+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
56+
/** @var \Magento\Cms\Model\Page $page */
57+
$page = $objectManager->create(\Magento\Cms\Model\Page::class);
58+
$page->setData(['title' => 'Test', 'stores' => [1]]);
59+
$page->setUpdateTime($updateTime);
60+
$page->save();
61+
$page = $objectManager->get(PageRepositoryInterface::class)->getById($page->getId());
62+
$this->assertEquals($updateTime, $page->getUpdateTime());
63+
}
64+
4765
public function generateIdentifierFromTitleDataProvider()
4866
{
4967
return [

lib/internal/Magento/Framework/EntityManager/Db/CreateRow.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterfa
5050
{
5151
$output = [];
5252
foreach ($connection->describeTable($metadata->getEntityTable()) as $column) {
53-
54-
if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP') {
53+
$columnName = strtolower($column['COLUMN_NAME']);
54+
if ($this->canNotSetTimeStamp($columnName, $column, $data)) {
5555
continue;
5656
}
57-
if (isset($data[strtolower($column['COLUMN_NAME'])])) {
57+
58+
if (isset($data[$columnName])) {
5859
$output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])];
5960
} elseif ($column['DEFAULT'] === null) {
6061
$output[strtolower($column['COLUMN_NAME'])] = null;
@@ -66,6 +67,18 @@ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterfa
6667
return $output;
6768
}
6869

70+
/**
71+
* @param string $columnName
72+
* @param string $column
73+
* @param array $data
74+
* @return bool
75+
*/
76+
private function canNotSetTimeStamp($columnName, $column, array $data)
77+
{
78+
return $column['DEFAULT'] == 'CURRENT_TIMESTAMP' && !isset($data[$columnName])
79+
&& empty($column['NULLABLE']);
80+
}
81+
6982
/**
7083
* @param string $entityType
7184
* @param array $data

lib/internal/Magento/Framework/EntityManager/Db/UpdateRow.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterfa
5050
{
5151
$output = [];
5252
foreach ($connection->describeTable($metadata->getEntityTable()) as $column) {
53-
if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP' || $column['IDENTITY']) {
53+
$columnName = strtolower($column['COLUMN_NAME']);
54+
if ($this->canNotSetTimeStamp($columnName, $column, $data) || $column['IDENTITY']) {
5455
continue;
5556
}
5657

57-
if (isset($data[strtolower($column['COLUMN_NAME'])])) {
58+
if (isset($data[$columnName])) {
5859
$output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])];
5960
} elseif (!empty($column['NULLABLE'])) {
6061
$output[strtolower($column['COLUMN_NAME'])] = null;
@@ -67,6 +68,18 @@ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterfa
6768
return $output;
6869
}
6970

71+
/**
72+
* @param string $columnName
73+
* @param string $column
74+
* @param array $data
75+
* @return bool
76+
*/
77+
private function canNotSetTimeStamp($columnName, $column, array $data)
78+
{
79+
return $column['DEFAULT'] == 'CURRENT_TIMESTAMP' && !isset($data[$columnName])
80+
&& empty($column['NULLABLE']);
81+
}
82+
7083
/**
7184
* @param string $entityType
7285
* @param array $data

lib/internal/Magento/Framework/EntityManager/Test/Unit/Db/UpdateRowTest.php

Lines changed: 79 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,14 @@ protected function setUp()
6363
]);
6464
}
6565

66-
public function testExecute()
66+
/**
67+
* @dataProvider columnsDataProvider
68+
* @param array $data
69+
* @param array $columns
70+
* @param array $preparedColumns
71+
*/
72+
public function testExecute(array $data, array $columns, array $preparedColumns)
6773
{
68-
$data = [
69-
'test_link_field' => 1,
70-
'identified_field' => 'test_identified_field',
71-
'test_simple' => 'test_value',
72-
];
73-
$columns = [
74-
'test_nullable' => [
75-
'NULLABLE' => true,
76-
'DEFAULT' => false,
77-
'IDENTITY' => false,
78-
'COLUMN_NAME' => 'test_nullable',
79-
],
80-
'test_simple' => [
81-
'NULLABLE' => true,
82-
'DEFAULT' => false,
83-
'IDENTITY' => false,
84-
'COLUMN_NAME' => 'test_simple',
85-
],
86-
];
87-
$preparedColumns = [
88-
'test_identified_field' => null,
89-
'test_nullable' => null,
90-
'test_simple' => 'test_value',
91-
];
92-
9374
$this->metadataPoolMock->expects($this->once())
9475
->method('getMetadata')
9576
->with('test')
@@ -115,7 +96,78 @@ public function testExecute()
11596
$this->metadataMock->expects($this->exactly(2))
11697
->method('getIdentifierField')
11798
->willReturn('test_identified_field');
118-
99+
if (empty($data['updated_at'])) {
100+
unset($data['updated_at']);
101+
}
119102
$this->assertSame($data, $this->model->execute('test', $data));
120103
}
104+
105+
/**
106+
* @return array
107+
*/
108+
public function columnsDataProvider()
109+
{
110+
$data = [
111+
'test_link_field' => 1,
112+
'identified_field' => 'test_identified_field',
113+
'test_simple' => 'test_value',
114+
];
115+
$columns = [
116+
'test_nullable' => [
117+
'NULLABLE' => true,
118+
'DEFAULT' => false,
119+
'IDENTITY' => false,
120+
'COLUMN_NAME' => 'test_nullable',
121+
],
122+
'test_simple' => [
123+
'NULLABLE' => true,
124+
'DEFAULT' => false,
125+
'IDENTITY' => false,
126+
'COLUMN_NAME' => 'test_simple',
127+
],
128+
];
129+
$preparedColumns = [
130+
'test_identified_field' => null,
131+
'test_nullable' => null,
132+
'test_simple' => 'test_value',
133+
];
134+
135+
return [
136+
'default' => [
137+
'data' => $data,
138+
'columns' => $columns,
139+
'preparedColumns' => $preparedColumns,
140+
],
141+
'empty timestamp field' => [
142+
'data' => array_merge($data, ['updated_at' => '']),
143+
'columns' => array_merge(
144+
$columns,
145+
[
146+
'updated_at' => [
147+
'NULLABLE' => false,
148+
'DEFAULT' => 'CURRENT_TIMESTAMP',
149+
'IDENTITY' => false,
150+
'COLUMN_NAME' => 'updated_at',
151+
],
152+
]
153+
),
154+
'preparedColumns' => $preparedColumns,
155+
],
156+
'filled timestamp field' => [
157+
'data' => array_merge($data, ['updated_at' => '2016-01-01 00:00:00']),
158+
'columns' => array_merge(
159+
$columns,
160+
[
161+
'updated_at' => [
162+
'NULLABLE' => false,
163+
'DEFAULT' => 'CURRENT_TIMESTAMP',
164+
'IDENTITY' => false,
165+
'COLUMN_NAME' => 'updated_at',
166+
],
167+
]
168+
),
169+
'preparedColumns' => array_merge($preparedColumns, ['updated_at' => '2016-01-01 00:00:00']),
170+
],
171+
];
172+
}
121173
}

0 commit comments

Comments
 (0)