Skip to content

Commit c429316

Browse files
author
Alexander Akimov
authored
Merge pull request #700 from magento-qmt/MTA-3984
[Mavericks] Extend functional tests coverage
2 parents 889ae4a + a4a229e commit c429316

33 files changed

+864
-53
lines changed

dev/tests/functional/.htaccess.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##############################################
22
## Allow access to command.php and website.php
3-
<FilesMatch "command.php|website.php">
3+
<FilesMatch "command.php|website.php|export.php">
44
order allow,deny
55
allow from all
66
</FilesMatch>

dev/tests/functional/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"magento/mtf": "1.0.0-rc50",
3+
"magento/mtf": "1.0.0-rc51",
44
"php": "~5.6.5|7.0.2|~7.0.6",
55
"phpunit/phpunit": "~4.8.0|~5.5.0",
66
"phpunit/phpunit-selenium": ">=1.2"

dev/tests/functional/etc/di.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,34 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<preference for="Magento\Mtf\Util\Command\File\ExportInterface" type="\Magento\Mtf\Util\Command\File\Export" />
10+
<preference for="Magento\Mtf\Util\Command\File\Export\ReaderInterface" type="\Magento\Mtf\Util\Command\File\Export\Reader" />
11+
12+
<type name="\Magento\Mtf\Util\Command\File\Export" shared="false" />
13+
914
<virtualType name="Magento\Mtf\Config\SchemaLocator\Config" type="Magento\Mtf\Config\SchemaLocator">
1015
<arguments>
1116
<argument name="schemaPath" xsi:type="string">etc/config.xsd</argument>
1217
</arguments>
1318
</virtualType>
1419

1520
<type name="Magento\Mtf\Util\Protocol\CurlTransport\WebapiDecorator" shared="true" />
21+
22+
<type name="Magento\Mtf\Util\Command\File\Export\Reader">
23+
<arguments>
24+
<argument name="template" xsi:type="string">\w*?\.csv</argument>
25+
</arguments>
26+
</type>
27+
28+
<virtualType name="Magento\Mtf\Util\Command\File\Export\ProductReader" type="Magento\Mtf\Util\Command\File\Export\Reader">
29+
<arguments>
30+
<argument name="template" xsi:type="string">catalog_product.*?\.csv</argument>
31+
</arguments>
32+
</virtualType>
33+
34+
<virtualType name="Magento\Mtf\Util\Command\File\Export\CustomerReader" type="Magento\Mtf\Util\Command\File\Export\Reader">
35+
<arguments>
36+
<argument name="template" xsi:type="string">customer.*?\.csv</argument>
37+
</arguments>
38+
</virtualType>
1639
</config>

dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\Mtf\Util\Command;
88

99
use Magento\Mtf\Util\Protocol\CurlInterface;
10-
use Magento\Mtf\ObjectManager;
1110
use Magento\Mtf\Util\Protocol\CurlTransport;
1211

1312
/**
@@ -28,7 +27,6 @@ class Cli
2827
private $transport;
2928

3029
/**
31-
* @constructor
3230
* @param CurlTransport $transport
3331
*/
3432
public function __construct(CurlTransport $transport)
@@ -61,6 +59,6 @@ protected function execute($command, $options = [])
6159
private function prepareUrl($command, array $options)
6260
{
6361
$command .= ' ' . implode(' ', $options);
64-
return $_ENV['app_frontend_url'] . Cli::URL . '?command=' . urlencode($command);
62+
return $_ENV['app_frontend_url'] . self::URL . '?command=' . urlencode($command);
6563
}
6664
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Mtf\Util\Command\File;
8+
9+
use Magento\Mtf\ObjectManagerInterface;
10+
use Magento\Mtf\Util\Command\File\Export\Data;
11+
use Magento\Mtf\Util\Command\File\Export\ReaderInterface;
12+
13+
/**
14+
* Get Exporting file from the Magento.
15+
*/
16+
class Export implements ExportInterface
17+
{
18+
/**
19+
* Path to the Reader.
20+
*
21+
* @var string
22+
*/
23+
private $readerPath = 'Magento\Mtf\Util\Command\File\Export\%sReader';
24+
25+
/**
26+
* Object manager instance.
27+
*
28+
* @var ObjectManagerInterface
29+
*/
30+
private $objectManager;
31+
32+
/**
33+
* File reader for Magento export files.
34+
*
35+
* @var ReaderInterface
36+
*/
37+
private $reader;
38+
39+
/**
40+
* @param ObjectManagerInterface $objectManager
41+
* @param string $type [optional]
42+
*/
43+
public function __construct(ObjectManagerInterface $objectManager, $type = 'product')
44+
{
45+
$this->objectManager = $objectManager;
46+
$this->reader = $this->getReader($type);
47+
}
48+
49+
/**
50+
* Get reader for export files.
51+
*
52+
* @param string $type
53+
* @return ReaderInterface
54+
* @throws \ReflectionException
55+
*/
56+
private function getReader($type)
57+
{
58+
$readerPath = sprintf($this->readerPath, ucfirst($type));
59+
try {
60+
return $this->objectManager->create($readerPath);
61+
} catch (\ReflectionException $e) {
62+
throw new \ReflectionException("Virtual type '$readerPath' does not exist. Please, check it in di.xml.");
63+
}
64+
}
65+
66+
/**
67+
* Get the export file by name.
68+
*
69+
* @param string $name
70+
* @return Data|null
71+
*/
72+
public function getByName($name)
73+
{
74+
$this->reader->getData();
75+
foreach ($this->reader->getData() as $file) {
76+
if ($file->getName() === $name) {
77+
return $file;
78+
}
79+
}
80+
81+
return null;
82+
}
83+
84+
/**
85+
* Get latest created the export file.
86+
*
87+
* @return Data|null
88+
*/
89+
public function getLatest()
90+
{
91+
$max = 0;
92+
$latest = null;
93+
foreach ($this->reader->getData() as $file) {
94+
if ($file->getDate() > $max) {
95+
$max = $file->getDate();
96+
$latest = $file;
97+
}
98+
}
99+
100+
return $latest;
101+
}
102+
103+
/**
104+
* Get all export files by date range using unix time stamp.
105+
*
106+
* @param string $start
107+
* @param string $end
108+
* @return Data[]
109+
*/
110+
public function getByDateRange($start, $end)
111+
{
112+
$files = [];
113+
foreach ($this->reader->getData() as $file) {
114+
if ($file->getDate() > $start && $file->getDate() < $end) {
115+
$files[] = $file;
116+
}
117+
}
118+
119+
return $files;
120+
}
121+
122+
/**
123+
* Get all export files.
124+
*
125+
* @return Data[]
126+
*/
127+
public function getAll()
128+
{
129+
return $this->reader->getData();
130+
}
131+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Mtf\Util\Command\File\Export;
8+
9+
/**
10+
* Data mapping for Export file.
11+
*/
12+
class Data
13+
{
14+
/**
15+
* File data.
16+
*
17+
* @var array
18+
*/
19+
private $data;
20+
21+
/**
22+
* @param array $data
23+
*/
24+
public function __construct(array $data)
25+
{
26+
$this->data = $data;
27+
}
28+
29+
/**
30+
* Get file name.
31+
*
32+
* @return string
33+
*/
34+
public function getName()
35+
{
36+
return $this->data['name'];
37+
}
38+
39+
/**
40+
* Get file content.
41+
*
42+
* @return string
43+
*/
44+
public function getContent()
45+
{
46+
return $this->data['content'];
47+
}
48+
49+
/**
50+
* Get file creation date.
51+
*
52+
* @return string
53+
*/
54+
public function getDate()
55+
{
56+
return $this->data['date'];
57+
}
58+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Mtf\Util\Command\File\Export;
8+
9+
use Magento\Mtf\ObjectManagerInterface;
10+
use Magento\Mtf\Util\Protocol\CurlTransport;
11+
use Magento\Mtf\Util\Protocol\CurlInterface;
12+
13+
/**
14+
* File reader for Magento export files.
15+
*/
16+
class Reader implements ReaderInterface
17+
{
18+
/**
19+
* Pattern for file name in Magento.
20+
*
21+
* @var string
22+
*/
23+
private $template;
24+
25+
/**
26+
* Object manager instance.
27+
*
28+
* @var ObjectManagerInterface
29+
*/
30+
private $objectManager;
31+
32+
/**
33+
* Curl transport protocol.
34+
*
35+
* @var CurlTransport
36+
*/
37+
private $transport;
38+
39+
/**
40+
* @param ObjectManagerInterface $objectManager
41+
* @param CurlTransport $transport
42+
* @param string $template
43+
*/
44+
public function __construct(ObjectManagerInterface $objectManager, CurlTransport $transport, $template)
45+
{
46+
$this->objectManager = $objectManager;
47+
$this->template = $template;
48+
$this->transport = $transport;
49+
}
50+
51+
/**
52+
* Exporting files as Data object from Magento.
53+
*
54+
* @return Data[]
55+
*/
56+
public function getData()
57+
{
58+
$data = [];
59+
foreach ($this->getFiles() as $file) {
60+
$data[] = $this->objectManager->create(Data::class, ['data' => $file]);
61+
}
62+
63+
return $data;
64+
}
65+
66+
/**
67+
* Get files by template from the Magento.
68+
*
69+
* @return array
70+
*/
71+
private function getFiles()
72+
{
73+
$this->transport->write($this->prepareUrl(), [], CurlInterface::GET);
74+
$serializedFiles = $this->transport->read();
75+
$this->transport->close();
76+
77+
return unserialize($serializedFiles);
78+
}
79+
80+
/**
81+
* Prepare url.
82+
*
83+
* @return string
84+
*/
85+
private function prepareUrl()
86+
{
87+
return $_ENV['app_frontend_url'] . self::URL . '?template=' . urlencode($this->template);
88+
}
89+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Mtf\Util\Command\File\Export;
8+
9+
/**
10+
* File reader interface for Magento export files.
11+
*/
12+
interface ReaderInterface
13+
{
14+
/**
15+
* Url to export.php.
16+
*/
17+
const URL = 'dev/tests/functional/utils/export.php';
18+
19+
/**
20+
* Exporting files as Data object from Magento.
21+
*
22+
* @return Data[]
23+
*/
24+
public function getData();
25+
}

0 commit comments

Comments
 (0)