From df97b72ce2364049ef2739a22c5bbaf6b1cdb4f2 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Fri, 30 Jan 2015 20:55:20 +0200 Subject: [PATCH 01/11] CRM-2441: MailChimp integration failed with more than 50 members - added reverse mode for BufferedQueryResultIterator --- .../ORM/Query/BufferedQueryResultIterator.php | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Oro/Bundle/BatchBundle/ORM/Query/BufferedQueryResultIterator.php b/src/Oro/Bundle/BatchBundle/ORM/Query/BufferedQueryResultIterator.php index e26677c5ffd..a0df6067457 100644 --- a/src/Oro/Bundle/BatchBundle/ORM/Query/BufferedQueryResultIterator.php +++ b/src/Oro/Bundle/BatchBundle/ORM/Query/BufferedQueryResultIterator.php @@ -108,6 +108,14 @@ class BufferedQueryResultIterator implements \Iterator, \Countable */ private $useCountWalker; + /** + * Walk through results in reverse order + * Useful when selected records are being updated in between page load + * + * @var bool|null + */ + private $isReverse; + /** * Constructor * @@ -164,6 +172,20 @@ public function setHydrationMode($hydrationMode) return $this; } + /** + * Sets reverse mode to be used to iterate results + * + * @param bool $isReverse + * @return BufferedQueryResultIterator + */ + public function setIsReverse($isReverse) + { + $this->assertQueryWasNotExecuted('reverse mode'); + $this->isReverse = $isReverse; + + return $this; + } + /** * {@inheritDoc} */ @@ -311,13 +333,25 @@ protected function loadNextPage() $query = $this->getQuery(); $totalPages = ceil($this->count() / $query->getMaxResults()); - if (!$totalPages || $totalPages <= $this->page + 1) { - unset($this->rows); + if ($this->isReverse) { + if ($this->page == -1) { + $this->page = $totalPages; + } + if ($this->page < 1) { + unset($this->rows); - return false; + return false; + } + $this->page--; + } else { + if (!$totalPages || $totalPages <= $this->page + 1) { + unset($this->rows); + + return false; + } + $this->page++; } - $this->page++; $this->offset = 0; $this->prepareQueryToExecute($query); From b061d5a17de7d6d3f6f16574b40e54367d28587d Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Tue, 10 Feb 2015 12:52:43 +0200 Subject: [PATCH 02/11] CRM-2441: MailChimp integration failed with more than 50 members - added unit test --- .../Query/BufferedQueryResultIteratorTest.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/Oro/Bundle/BatchBundle/Tests/Unit/ORM/Query/BufferedQueryResultIteratorTest.php b/src/Oro/Bundle/BatchBundle/Tests/Unit/ORM/Query/BufferedQueryResultIteratorTest.php index ae93dd46261..dc0299e8742 100644 --- a/src/Oro/Bundle/BatchBundle/Tests/Unit/ORM/Query/BufferedQueryResultIteratorTest.php +++ b/src/Oro/Bundle/BatchBundle/Tests/Unit/ORM/Query/BufferedQueryResultIteratorTest.php @@ -502,4 +502,63 @@ function ($sql) use (&$statements, &$statementCounter, &$actualSqls) { $actualSqls[1] ); } + + public function testIteratorInReverseDirection() + { + $records = [ + ['a0' => '1'], + ['a0' => '2'], + ['a0' => '3'], + ]; + $actualSqls = []; + $statementCounter = 0; + $statements = [ + $this->createFetchStatementMock([['sclr0' => count($records)]]), + $this->createFetchStatementMock([$records[0], $records[1]]), + $this->createFetchStatementMock([$records[2]]) + ]; + + $this->getDriverConnectionMock($this->em)->expects($this->any()) + ->method('query') + ->will( + $this->returnCallback( + function ($sql) use (&$statements, &$statementCounter, &$actualSqls) { + $actualSqls[$statementCounter] = $sql; + $statement = $statements[$statementCounter]; + $statementCounter++; + return $statement; + } + ) + ); + + $source = $this->em->createQueryBuilder() + ->select('o') + ->from('Stub:Entity', 'o'); + + $iterator = new BufferedQueryResultIterator($source); + $iterator->setIsReverse(true); + $iterator->setBufferSize(2); + + $this->assertEquals(count($records), $iterator->count()); + $count = 0; + foreach ($iterator as $record) { + $this->assertInstanceOf('Oro\Bundle\BatchBundle\Tests\Unit\ORM\Query\Stub\Entity', $record); + $this->assertEquals($records[$count]['a0'], $record->a); + $count++; + } + $this->assertEquals(count($records), $count); + $this->assertCount(3, $actualSqls); + $this->assertEquals( + 'SELECT count(e0_.a) AS sclr0 FROM Entity e0_', + $actualSqls[0] + ); + $this->assertEquals( + 'SELECT e0_.a AS a0, e0_.b AS b1 FROM Entity e0_ LIMIT 2 OFFSET 2', + $actualSqls[1] + ); + $this->assertEquals( + 'SELECT e0_.a AS a0, e0_.b AS b1 FROM Entity e0_ LIMIT 2 OFFSET 0', + $actualSqls[2] + ); + } } From cc3dc86ba0a19b757150b6b0b79665db691a6941 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Tue, 10 Feb 2015 20:49:18 +0200 Subject: [PATCH 03/11] CRM-2441: MailChimp integration failed with more than 50 members - fixed name select quieries --- .../ORM/Query/BufferedQueryResultIterator.php | 14 +++++++------- .../ORM/Query/BufferedQueryResultIteratorTest.php | 2 +- .../Bundle/LocaleBundle/DQL/DQLNameFormatter.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Oro/Bundle/BatchBundle/ORM/Query/BufferedQueryResultIterator.php b/src/Oro/Bundle/BatchBundle/ORM/Query/BufferedQueryResultIterator.php index a0df6067457..28c537ac424 100644 --- a/src/Oro/Bundle/BatchBundle/ORM/Query/BufferedQueryResultIterator.php +++ b/src/Oro/Bundle/BatchBundle/ORM/Query/BufferedQueryResultIterator.php @@ -112,9 +112,9 @@ class BufferedQueryResultIterator implements \Iterator, \Countable * Walk through results in reverse order * Useful when selected records are being updated in between page load * - * @var bool|null + * @var bool */ - private $isReverse; + private $reverse = false; /** * Constructor @@ -173,15 +173,15 @@ public function setHydrationMode($hydrationMode) } /** - * Sets reverse mode to be used to iterate results + * Sets iteration order * - * @param bool $isReverse + * @param bool $reverse Determines the iteration order * @return BufferedQueryResultIterator */ - public function setIsReverse($isReverse) + public function setReverse($reverse) { $this->assertQueryWasNotExecuted('reverse mode'); - $this->isReverse = $isReverse; + $this->reverse = $reverse; return $this; } @@ -333,7 +333,7 @@ protected function loadNextPage() $query = $this->getQuery(); $totalPages = ceil($this->count() / $query->getMaxResults()); - if ($this->isReverse) { + if ($this->reverse) { if ($this->page == -1) { $this->page = $totalPages; } diff --git a/src/Oro/Bundle/BatchBundle/Tests/Unit/ORM/Query/BufferedQueryResultIteratorTest.php b/src/Oro/Bundle/BatchBundle/Tests/Unit/ORM/Query/BufferedQueryResultIteratorTest.php index dc0299e8742..2921984e446 100644 --- a/src/Oro/Bundle/BatchBundle/Tests/Unit/ORM/Query/BufferedQueryResultIteratorTest.php +++ b/src/Oro/Bundle/BatchBundle/Tests/Unit/ORM/Query/BufferedQueryResultIteratorTest.php @@ -536,7 +536,7 @@ function ($sql) use (&$statements, &$statementCounter, &$actualSqls) { ->from('Stub:Entity', 'o'); $iterator = new BufferedQueryResultIterator($source); - $iterator->setIsReverse(true); + $iterator->setReverse(true); $iterator->setBufferSize(2); $this->assertEquals(count($records), $iterator->count()); diff --git a/src/Oro/Bundle/LocaleBundle/DQL/DQLNameFormatter.php b/src/Oro/Bundle/LocaleBundle/DQL/DQLNameFormatter.php index 07a950b67e8..e2e20bcc236 100644 --- a/src/Oro/Bundle/LocaleBundle/DQL/DQLNameFormatter.php +++ b/src/Oro/Bundle/LocaleBundle/DQL/DQLNameFormatter.php @@ -110,7 +110,7 @@ private function buildExpression($nameFormat, array $nameParts) * * @return array */ - private function extractNamePartsPaths($className, $relationAlias) + public function extractNamePartsPaths($className, $relationAlias) { $nameParts = array_fill_keys(array_keys($this->namePartsMap), null); $interfaces = class_implements($className); From 7734f22069029d244188e9509e3dcc97c049de99 Mon Sep 17 00:00:00 2001 From: Alex Kuzmenko Date: Thu, 15 Jan 2015 19:31:25 +0200 Subject: [PATCH 04/11] OEE-507: Some settings disappear from System configuration --- .../Form/Type/DownloadLinksType.php | 85 +++++++++++ .../FormBundle/Resources/config/form_type.yml | 9 ++ .../Resources/views/Form/fields.html.twig | 23 ++- .../Unit/Form/Type/DownloadLinksTypeTest.php | 143 ++++++++++++++++++ 4 files changed, 248 insertions(+), 12 deletions(-) create mode 100644 src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php create mode 100644 src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php diff --git a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php new file mode 100644 index 00000000000..9a0dc731d81 --- /dev/null +++ b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php @@ -0,0 +1,85 @@ +assetHelper = $assetHelper; + } + + /** + * {@inheritdoc} + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $resolver + ->setRequired(['source']) + ->setOptional(['class']) + ->setDefaults(['class' => '']) + ->setAllowedTypes(['source' => 'array']); + } + + /** + * {@inheritdoc} + */ + public function finishView(FormView $view, FormInterface $form, array $options) + { + $view->vars['files'] = $this->getFiles($options['source']); + $view->vars['class'] = $options['class']; + } + + /** + * {@inheritdoc} + */ + public function getParent() + { + return 'text'; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'oro_download_links_type'; + } + + /** + * Get files from a specified source data + * + * @param array $source + * @return array + */ + public function getFiles($source) + { + $resources = []; + if (isset($source['path'], $source['url'])) { + $finder = new Finder(); + $pathParts = explode('/', $source['path']); + $fileNamePattern = array_pop($pathParts); + $files = $finder->name($fileNamePattern)->in(implode('/', $pathParts)); + foreach ($files as $file) { + $resources[$file->getFilename()] = $this->assetHelper->getUrl( + $source['url'] . DIRECTORY_SEPARATOR . $file->getFilename() + ); + } + } + + return $resources; + } +} diff --git a/src/Oro/Bundle/FormBundle/Resources/config/form_type.yml b/src/Oro/Bundle/FormBundle/Resources/config/form_type.yml index 31de7a86b75..8a0b93d6137 100644 --- a/src/Oro/Bundle/FormBundle/Resources/config/form_type.yml +++ b/src/Oro/Bundle/FormBundle/Resources/config/form_type.yml @@ -17,6 +17,7 @@ parameters: oro_form.type.simple_color_choice.class: Oro\Bundle\FormBundle\Form\Type\OroSimpleColorChoiceType oro_form.type.color_table.class: Oro\Bundle\FormBundle\Form\Type\OroColorTableType oro_form.type.link.class: Oro\Bundle\FormBundle\Form\Type\LinkType + oro_form.type.download_links.class: Oro\Bundle\FormBundle\Form\Type\DownloadLinksType oro_form.type.api.class: Oro\Bundle\FormBundle\Form\Type\AbstractApiType oro_form.extension.data_block.class: Oro\Bundle\FormBundle\Form\Extension\DataBlockExtension @@ -192,6 +193,14 @@ services: tags: - { name: form.type, alias: oro_link_type } + oro_form.type.download_links: + class: %oro_form.type.download_links.class% + arguments: + - @templating.helper.assets + scope: request + tags: + - { name: form.type, alias: oro_download_links_type } + oro_form.type.api: class: %oro_form.type.api.class% tags: diff --git a/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig b/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig index 709a5ff5a75..fcdfc5e9d70 100644 --- a/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig +++ b/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig @@ -679,21 +679,20 @@ {% block oro_link_type_widget %} {% if isPath or resource_granted(acl) %} {# @todo after BAP-4696 implementation remove isPath from condition #} - {# @todo after BAP-4696 implementation remove link class #} - {% if value is defined and value is iterable%} - {% for fileName, route in value %} - - {{ fileName }} - - {% endfor %} - {% else %} - - {{ title|trans }} - - {% endif %} + + {{ title|trans }} + {% endif %} {% endblock %} +{% block oro_download_links_type_widget %} + {% for fileName, route in files %} + + {{ fileName }} + + {% endfor %} +{% endblock %} + {% block oro_simple_color_picker_row %} {{ block('form_row') }} {% endblock %} diff --git a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php new file mode 100644 index 00000000000..8e818e30d38 --- /dev/null +++ b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php @@ -0,0 +1,143 @@ +assetHelper = $this->getMockBuilder('Symfony\Component\Templating\Helper\CoreAssetsHelper') + ->disableOriginalConstructor() + ->getMock(); + $this->type = new DownloadLinksType($this->assetHelper); + } + + public function testGetName() + { + $this->assertInternalType('string', $this->type->getName()); + $this->assertEquals('oro_download_links_type', $this->type->getName()); + } + + public function testGetParent() + { + $this->assertInternalType('string', $this->type->getParent()); + $this->assertEquals('text', $this->type->getParent()); + } + + public function testSetDefaultOptions() + { + $resolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface'); + + $resolver + ->expects($this->once()) + ->method('setRequired') + ->with($this->isType('array')) + ->will($this->returnSelf()); + + $resolver + ->expects($this->once()) + ->method('setOptional') + ->with($this->isType('array')) + ->will($this->returnSelf()); + + $resolver + ->expects($this->once()) + ->method('setDefaults') + ->with($this->isType('array')) + ->will($this->returnSelf()); + + $resolver + ->expects($this->once()) + ->method('setAllowedTypes') + ->with($this->isType('array')) + ->will($this->returnSelf()); + + $this->type->setDefaultOptions($resolver); + } + + /** + * @param array $files + * @param array $options + * @param array $expected + * @dataProvider optionsProvider + */ + public function testFinishView(array $files, array $options, array $expected) + { + $formView = $this->getMock('Symfony\Component\Form\FormView'); + $form = $this->getMockBuilder('Symfony\Component\Form\Form') + ->disableOriginalConstructor() + ->getMock(); + + $valueMap = []; + foreach ($files as $fileName) { + file_put_contents(sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName, ''); + if (isset($expected['files'][$fileName])) { + array_push( + $valueMap, + [ + $options['source']['url'] . DIRECTORY_SEPARATOR . $fileName, + null, + $expected['files'][$fileName] + ] + ); + } + + } + $this->assetHelper + ->expects($this->exactly(count($files))) + ->method('getUrl') + ->will($this->returnValueMap($valueMap)); + + $this->type->finishView($formView, $form, $options); + $this->assertEquals($expected, $formView->vars); + + foreach ($files as $fileName) { + unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName); + } + } + + /** + * @return array + */ + public function optionsProvider() + { + return [ + [ + [ + 'file1.txt', + 'file2.txt', + ], + [ + 'source' => [ + 'path' => sys_get_temp_dir() . '/*.txt', + 'url' => 'download/files' + ], + 'class' => 'red' + ], + [ + 'value' => null, + 'attr' => [], + 'files' => [ + 'file1.txt' => '/download/files/file1.txt', + 'file2.txt' => '/download/files/file2.txt' + ], + 'class' => 'red' + ] + ] + ]; + } +} From 8889bfa6a74324b7d88a3dc9372fa639460c8d01 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Fri, 16 Jan 2015 00:34:07 +0200 Subject: [PATCH 05/11] OEE-507: Some settings disappear from System configuration --- .../Form/Type/DownloadLinksType.php | 8 -- .../Unit/Form/Type/DownloadLinksTypeTest.php | 103 +++++++++++------- 2 files changed, 61 insertions(+), 50 deletions(-) diff --git a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php index 9a0dc731d81..69ba83ff68d 100644 --- a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php +++ b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php @@ -43,14 +43,6 @@ public function finishView(FormView $view, FormInterface $form, array $options) $view->vars['class'] = $options['class']; } - /** - * {@inheritdoc} - */ - public function getParent() - { - return 'text'; - } - /** * {@inheritdoc} */ diff --git a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php index 8e818e30d38..68e34852b37 100644 --- a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php +++ b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php @@ -2,11 +2,14 @@ namespace Oro\Bundle\FormBundle\Tests\Unit\Form\Type; +use Symfony\Component\Form\FormView; +use Symfony\Component\Form\Test\FormIntegrationTestCase; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Templating\Helper\CoreAssetsHelper; use Oro\Bundle\FormBundle\Form\Type\DownloadLinksType; -class DownloadLinksTypeTest extends \PHPUnit_Framework_TestCase +class DownloadLinksTypeTest extends FormIntegrationTestCase { /** * @var DownloadLinksType @@ -20,9 +23,9 @@ class DownloadLinksTypeTest extends \PHPUnit_Framework_TestCase protected function setUp() { + parent::setUp(); $this->assetHelper = $this->getMockBuilder('Symfony\Component\Templating\Helper\CoreAssetsHelper') - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor()->getMock(); $this->type = new DownloadLinksType($this->assetHelper); } @@ -32,41 +35,31 @@ public function testGetName() $this->assertEquals('oro_download_links_type', $this->type->getName()); } - public function testGetParent() + /** + * @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException + * @expectedExceptionMessage The required option "source" is missing. + */ + public function testSetDefaultOptionsWithoutSource() { - $this->assertInternalType('string', $this->type->getParent()); - $this->assertEquals('text', $this->type->getParent()); + $resolver = $this->getOptionsResolver(); + $this->type->setDefaultOptions($resolver); + $resolver->resolve([]); } public function testSetDefaultOptions() { - $resolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface'); - - $resolver - ->expects($this->once()) - ->method('setRequired') - ->with($this->isType('array')) - ->will($this->returnSelf()); - - $resolver - ->expects($this->once()) - ->method('setOptional') - ->with($this->isType('array')) - ->will($this->returnSelf()); - - $resolver - ->expects($this->once()) - ->method('setDefaults') - ->with($this->isType('array')) - ->will($this->returnSelf()); - - $resolver - ->expects($this->once()) - ->method('setAllowedTypes') - ->with($this->isType('array')) - ->will($this->returnSelf()); - + $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); + + $options = ['source' => []]; + $resolvedOptions = $resolver->resolve($options); + $this->assertEquals( + [ + 'source' => [], + 'class' => '' + ], + $resolvedOptions + ); } /** @@ -77,10 +70,9 @@ public function testSetDefaultOptions() */ public function testFinishView(array $files, array $options, array $expected) { - $formView = $this->getMock('Symfony\Component\Form\FormView'); - $form = $this->getMockBuilder('Symfony\Component\Form\Form') - ->disableOriginalConstructor() - ->getMock(); + $form = $this->getMockBuilder('Symfony\Component\Form\Form') + ->disableOriginalConstructor()->getMock(); + $view = new FormView(); $valueMap = []; foreach ($files as $fileName) { @@ -102,8 +94,8 @@ public function testFinishView(array $files, array $options, array $expected) ->method('getUrl') ->will($this->returnValueMap($valueMap)); - $this->type->finishView($formView, $form, $options); - $this->assertEquals($expected, $formView->vars); + $this->type->finishView($view, $form, $options); + $this->assertEquals($expected, $view->vars); foreach ($files as $fileName) { unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName); @@ -116,19 +108,35 @@ public function testFinishView(array $files, array $options, array $expected) public function optionsProvider() { return [ - [ - [ + 'no files' => [ + 'files' => [], + 'options' => [ + 'source' => [ + 'path' => sys_get_temp_dir() . '/*.txt', + 'url' => 'download/files' + ], + 'class' => '' + ], + 'expected' => [ + 'value' => null, + 'attr' => [], + 'files' => [], + 'class' => '' + ] + ], + 'existing files' => [ + 'files' => [ 'file1.txt', 'file2.txt', ], - [ + 'options' => [ 'source' => [ 'path' => sys_get_temp_dir() . '/*.txt', 'url' => 'download/files' ], 'class' => 'red' ], - [ + 'expected' => [ 'value' => null, 'attr' => [], 'files' => [ @@ -140,4 +148,15 @@ public function optionsProvider() ] ]; } + + /** + * @return OptionsResolver + */ + protected function getOptionsResolver() + { + $resolver = new OptionsResolver(); + $resolver->setDefaults([]); + + return $resolver; + } } From 0af79cd6e81b9fa501006f5b82586535cd9d2bb9 Mon Sep 17 00:00:00 2001 From: Alexandr Smaga Date: Fri, 16 Jan 2015 17:09:14 +0200 Subject: [PATCH 06/11] OEE-507: Some settings disappear from System configuration - minor code style fixes --- .../Form/Type/DownloadLinksType.php | 1 + .../FormBundle/Resources/config/form_type.yml | 2 +- .../Resources/views/Form/fields.html.twig | 12 ++-- .../Unit/Form/Type/DownloadLinksTypeTest.php | 71 +++++++------------ 4 files changed, 35 insertions(+), 51 deletions(-) diff --git a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php index 69ba83ff68d..eb3439e93d6 100644 --- a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php +++ b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php @@ -65,6 +65,7 @@ public function getFiles($source) $pathParts = explode('/', $source['path']); $fileNamePattern = array_pop($pathParts); $files = $finder->name($fileNamePattern)->in(implode('/', $pathParts)); + /** @var \SplFileInfo[] $files */ foreach ($files as $file) { $resources[$file->getFilename()] = $this->assetHelper->getUrl( $source['url'] . DIRECTORY_SEPARATOR . $file->getFilename() diff --git a/src/Oro/Bundle/FormBundle/Resources/config/form_type.yml b/src/Oro/Bundle/FormBundle/Resources/config/form_type.yml index 8a0b93d6137..082a4885a9f 100644 --- a/src/Oro/Bundle/FormBundle/Resources/config/form_type.yml +++ b/src/Oro/Bundle/FormBundle/Resources/config/form_type.yml @@ -17,7 +17,7 @@ parameters: oro_form.type.simple_color_choice.class: Oro\Bundle\FormBundle\Form\Type\OroSimpleColorChoiceType oro_form.type.color_table.class: Oro\Bundle\FormBundle\Form\Type\OroColorTableType oro_form.type.link.class: Oro\Bundle\FormBundle\Form\Type\LinkType - oro_form.type.download_links.class: Oro\Bundle\FormBundle\Form\Type\DownloadLinksType + oro_form.type.download_links.class: Oro\Bundle\FormBundle\Form\Type\DownloadLinksType oro_form.type.api.class: Oro\Bundle\FormBundle\Form\Type\AbstractApiType oro_form.extension.data_block.class: Oro\Bundle\FormBundle\Form\Extension\DataBlockExtension diff --git a/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig b/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig index fcdfc5e9d70..3e8cd402e11 100644 --- a/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig +++ b/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig @@ -686,11 +686,13 @@ {% endblock %} {% block oro_download_links_type_widget %} - {% for fileName, route in files %} - - {{ fileName }} - - {% endfor %} + {% spaceless %} + {% for fileName, route in files %} + + {{ fileName }} + + {% endfor %} + {% endspaceless %} {% endblock %} {% block oro_simple_color_picker_row %} diff --git a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php index 68e34852b37..6241be3a2c9 100644 --- a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php +++ b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php @@ -3,30 +3,24 @@ namespace Oro\Bundle\FormBundle\Tests\Unit\Form\Type; use Symfony\Component\Form\FormView; -use Symfony\Component\Form\Test\FormIntegrationTestCase; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Templating\Helper\CoreAssetsHelper; use Oro\Bundle\FormBundle\Form\Type\DownloadLinksType; -class DownloadLinksTypeTest extends FormIntegrationTestCase +class DownloadLinksTypeTest extends \PHPUnit_Framework_TestCase { - /** - * @var DownloadLinksType - */ + /** @var DownloadLinksType */ protected $type; - /** - * @var CoreAssetsHelper - */ + /** @var CoreAssetsHelper|\PHPUnit_Framework_MockObject_MockObject */ protected $assetHelper; protected function setUp() { - parent::setUp(); $this->assetHelper = $this->getMockBuilder('Symfony\Component\Templating\Helper\CoreAssetsHelper') ->disableOriginalConstructor()->getMock(); - $this->type = new DownloadLinksType($this->assetHelper); + $this->type = new DownloadLinksType($this->assetHelper); } public function testGetName() @@ -41,17 +35,17 @@ public function testGetName() */ public function testSetDefaultOptionsWithoutSource() { - $resolver = $this->getOptionsResolver(); + $resolver = new OptionsResolver(); $this->type->setDefaultOptions($resolver); $resolver->resolve([]); } public function testSetDefaultOptions() { - $resolver = $this->getOptionsResolver(); + $resolver = new OptionsResolver(); $this->type->setDefaultOptions($resolver); - $options = ['source' => []]; + $options = ['source' => []]; $resolvedOptions = $resolver->resolve($options); $this->assertEquals( [ @@ -66,12 +60,12 @@ public function testSetDefaultOptions() * @param array $files * @param array $options * @param array $expected + * * @dataProvider optionsProvider */ public function testFinishView(array $files, array $options, array $expected) { - $form = $this->getMockBuilder('Symfony\Component\Form\Form') - ->disableOriginalConstructor()->getMock(); + $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); $view = new FormView(); $valueMap = []; @@ -89,10 +83,8 @@ public function testFinishView(array $files, array $options, array $expected) } } - $this->assetHelper - ->expects($this->exactly(count($files))) - ->method('getUrl') - ->will($this->returnValueMap($valueMap)); + $this->assetHelper->expects($this->exactly(count($files)))->method('getUrl') + ->willReturnMap($valueMap); $this->type->finishView($view, $form, $options); $this->assertEquals($expected, $view->vars); @@ -108,55 +100,44 @@ public function testFinishView(array $files, array $options, array $expected) public function optionsProvider() { return [ - 'no files' => [ + 'no files' => [ 'files' => [], 'options' => [ 'source' => [ - 'path' => sys_get_temp_dir() . '/*.txt', + 'path' => sys_get_temp_dir() . '/*.download_file', 'url' => 'download/files' ], 'class' => '' ], 'expected' => [ - 'value' => null, - 'attr' => [], - 'files' => [], - 'class' => '' + 'value' => null, + 'attr' => [], + 'files' => [], + 'class' => '' ] ], 'existing files' => [ 'files' => [ - 'file1.txt', - 'file2.txt', + 'file1.download_file', + 'file2.download_file', ], 'options' => [ 'source' => [ - 'path' => sys_get_temp_dir() . '/*.txt', + 'path' => sys_get_temp_dir() . '/*.download_file', 'url' => 'download/files' ], 'class' => 'red' ], 'expected' => [ - 'value' => null, - 'attr' => [], - 'files' => [ - 'file1.txt' => '/download/files/file1.txt', - 'file2.txt' => '/download/files/file2.txt' + 'value' => null, + 'attr' => [], + 'files' => [ + 'file1.download_file' => '/download/files/file1.download_file', + 'file2.download_file' => '/download/files/file2.download_file' ], - 'class' => 'red' + 'class' => 'red' ] ] ]; } - - /** - * @return OptionsResolver - */ - protected function getOptionsResolver() - { - $resolver = new OptionsResolver(); - $resolver->setDefaults([]); - - return $resolver; - } } From 3dca35dc2f3b126372ba86a3095882e7d98afb74 Mon Sep 17 00:00:00 2001 From: Alexandr Smaga Date: Fri, 16 Jan 2015 18:34:04 +0200 Subject: [PATCH 07/11] OEE-507: Some settings disappear from System configuration - minor fixes --- src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php index eb3439e93d6..a4a61ecae38 100644 --- a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php +++ b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php @@ -68,7 +68,7 @@ public function getFiles($source) /** @var \SplFileInfo[] $files */ foreach ($files as $file) { $resources[$file->getFilename()] = $this->assetHelper->getUrl( - $source['url'] . DIRECTORY_SEPARATOR . $file->getFilename() + rtrim($source['url'], '/') . '/' . $file->getFilename() ); } } From ba5fc7aaa08488389c6a5b319d0bad9fba652a46 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Mon, 19 Jan 2015 17:01:32 +0200 Subject: [PATCH 08/11] OEE-507: Some settings disappear from System configuration - unit test fix --- .../Form/Type/DownloadLinksType.php | 5 +- .../Unit/Form/Type/DownloadLinksTypeTest.php | 57 ++++++++++++++++--- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php index a4a61ecae38..cb1b332c746 100644 --- a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php +++ b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php @@ -59,13 +59,12 @@ public function getName() */ public function getFiles($source) { - $resources = []; + $resources = []; if (isset($source['path'], $source['url'])) { $finder = new Finder(); $pathParts = explode('/', $source['path']); $fileNamePattern = array_pop($pathParts); - $files = $finder->name($fileNamePattern)->in(implode('/', $pathParts)); - /** @var \SplFileInfo[] $files */ + $files = $finder->name($fileNamePattern)->in(implode(DIRECTORY_SEPARATOR, $pathParts)); foreach ($files as $file) { $resources[$file->getFilename()] = $this->assetHelper->getUrl( rtrim($source['url'], '/') . '/' . $file->getFilename() diff --git a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php index 6241be3a2c9..da9359d9a7f 100644 --- a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php +++ b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php @@ -16,11 +16,25 @@ class DownloadLinksTypeTest extends \PHPUnit_Framework_TestCase /** @var CoreAssetsHelper|\PHPUnit_Framework_MockObject_MockObject */ protected $assetHelper; + /** @var string */ + protected $testDir; + protected function setUp() { $this->assetHelper = $this->getMockBuilder('Symfony\Component\Templating\Helper\CoreAssetsHelper') ->disableOriginalConstructor()->getMock(); $this->type = new DownloadLinksType($this->assetHelper); + + $this->removeTestDir($this->getTestDir()); + if (!is_dir($this->testDir)) { + mkdir($this->testDir); + } + } + + protected function tearDown() + { + $this->removeTestDir(); + unset($this->testDir, $this->type, $this->assetHelper); } public function testGetName() @@ -70,7 +84,7 @@ public function testFinishView(array $files, array $options, array $expected) $valueMap = []; foreach ($files as $fileName) { - file_put_contents(sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName, ''); + file_put_contents($this->testDir . DIRECTORY_SEPARATOR . $fileName, ''); if (isset($expected['files'][$fileName])) { array_push( $valueMap, @@ -88,10 +102,6 @@ public function testFinishView(array $files, array $options, array $expected) $this->type->finishView($view, $form, $options); $this->assertEquals($expected, $view->vars); - - foreach ($files as $fileName) { - unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName); - } } /** @@ -104,7 +114,7 @@ public function optionsProvider() 'files' => [], 'options' => [ 'source' => [ - 'path' => sys_get_temp_dir() . '/*.download_file', + 'path' => $this->getTestDir() . '/*.download_file', 'url' => 'download/files' ], 'class' => '' @@ -123,7 +133,7 @@ public function optionsProvider() ], 'options' => [ 'source' => [ - 'path' => sys_get_temp_dir() . '/*.download_file', + 'path' => $this->getTestDir() . '/*.download_file', 'url' => 'download/files' ], 'class' => 'red' @@ -140,4 +150,37 @@ public function optionsProvider() ] ]; } + + /** + * Get test dir path + * + * @return string + */ + protected function getTestDir() + { + if (!isset($this->testDir)) { + $tmpDir = ini_get('upload_tmp_dir'); + if (!$tmpDir || !is_dir($tmpDir) || !is_writable($tmpDir)) { + $tmpDir = sys_get_temp_dir(); + } + $this->testDir = $tmpDir . DIRECTORY_SEPARATOR . 'oro_download_dir'; + } + + return $this->testDir; + } + + /** + * Remove test dir + */ + protected function removeTestDir() + { + if (is_dir($this->testDir)) { + $files = new \RecursiveDirectoryIterator($this->testDir, \RecursiveDirectoryIterator::SKIP_DOTS); + foreach ($files as $fileInfo) { + unlink($fileInfo->getRealPath()); + } + + rmdir($this->testDir); + } + } } From 1753bef2f5e6527866b7be41b90fc69e93a910da Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenko Date: Mon, 19 Jan 2015 17:54:46 +0200 Subject: [PATCH 09/11] OEE-507: Some settings disappear from System configuration - fix for unit test on windows - minor fixes --- .../Form/Type/DownloadLinksType.php | 1 + .../Unit/Form/Type/DownloadLinksTypeTest.php | 21 +++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php index cb1b332c746..e3849de4569 100644 --- a/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php +++ b/src/Oro/Bundle/FormBundle/Form/Type/DownloadLinksType.php @@ -65,6 +65,7 @@ public function getFiles($source) $pathParts = explode('/', $source['path']); $fileNamePattern = array_pop($pathParts); $files = $finder->name($fileNamePattern)->in(implode(DIRECTORY_SEPARATOR, $pathParts)); + /** @var \SplFileInfo[] $files */ foreach ($files as $file) { $resources[$file->getFilename()] = $this->assetHelper->getUrl( rtrim($source['url'], '/') . '/' . $file->getFilename() diff --git a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php index da9359d9a7f..64484c2353b 100644 --- a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php +++ b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php @@ -24,11 +24,9 @@ protected function setUp() $this->assetHelper = $this->getMockBuilder('Symfony\Component\Templating\Helper\CoreAssetsHelper') ->disableOriginalConstructor()->getMock(); $this->type = new DownloadLinksType($this->assetHelper); - - $this->removeTestDir($this->getTestDir()); - if (!is_dir($this->testDir)) { - mkdir($this->testDir); - } + $this->testDir = $this->getTestDir(); + $this->removeTestDir(); + mkdir($this->testDir); } protected function tearDown() @@ -89,7 +87,7 @@ public function testFinishView(array $files, array $options, array $expected) array_push( $valueMap, [ - $options['source']['url'] . DIRECTORY_SEPARATOR . $fileName, + $options['source']['url'] . '/' . $fileName, null, $expected['files'][$fileName] ] @@ -158,15 +156,12 @@ public function optionsProvider() */ protected function getTestDir() { - if (!isset($this->testDir)) { - $tmpDir = ini_get('upload_tmp_dir'); - if (!$tmpDir || !is_dir($tmpDir) || !is_writable($tmpDir)) { - $tmpDir = sys_get_temp_dir(); - } - $this->testDir = $tmpDir . DIRECTORY_SEPARATOR . 'oro_download_dir'; + $tmpDir = ini_get('upload_tmp_dir'); + if (!$tmpDir || !is_dir($tmpDir) || !is_writable($tmpDir)) { + $tmpDir = sys_get_temp_dir(); } - return $this->testDir; + return $tmpDir . DIRECTORY_SEPARATOR . 'oro_download_dir'; } /** From fbcc96075d915becc5242a7df745df5ec1b3ca8b Mon Sep 17 00:00:00 2001 From: Alexandr Smaga Date: Mon, 19 Jan 2015 18:57:08 +0200 Subject: [PATCH 10/11] OEE-507: Some settings disappear from System configuration - code style fixes --- .../Unit/Form/Type/DownloadLinksTypeTest.php | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php index 64484c2353b..2f8f976302d 100644 --- a/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php +++ b/src/Oro/Bundle/FormBundle/Tests/Unit/Form/Type/DownloadLinksTypeTest.php @@ -16,23 +16,15 @@ class DownloadLinksTypeTest extends \PHPUnit_Framework_TestCase /** @var CoreAssetsHelper|\PHPUnit_Framework_MockObject_MockObject */ protected $assetHelper; - /** @var string */ - protected $testDir; - protected function setUp() { - $this->assetHelper = $this->getMockBuilder('Symfony\Component\Templating\Helper\CoreAssetsHelper') - ->disableOriginalConstructor()->getMock(); + $this->assetHelper = $this->getMock('Symfony\Component\Templating\Helper\CoreAssetsHelper', [], [], '', false); $this->type = new DownloadLinksType($this->assetHelper); - $this->testDir = $this->getTestDir(); - $this->removeTestDir(); - mkdir($this->testDir); } protected function tearDown() { - $this->removeTestDir(); - unset($this->testDir, $this->type, $this->assetHelper); + unset($this->type, $this->assetHelper); } public function testGetName() @@ -77,12 +69,16 @@ public function testSetDefaultOptions() */ public function testFinishView(array $files, array $options, array $expected) { + $testDir = $this->getTestDir(); + $this->removeTestDir($testDir); + mkdir($testDir); + $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); $view = new FormView(); $valueMap = []; foreach ($files as $fileName) { - file_put_contents($this->testDir . DIRECTORY_SEPARATOR . $fileName, ''); + file_put_contents($testDir . DIRECTORY_SEPARATOR . $fileName, ''); if (isset($expected['files'][$fileName])) { array_push( $valueMap, @@ -100,6 +96,8 @@ public function testFinishView(array $files, array $options, array $expected) $this->type->finishView($view, $form, $options); $this->assertEquals($expected, $view->vars); + + $this->removeTestDir($testDir); } /** @@ -112,7 +110,7 @@ public function optionsProvider() 'files' => [], 'options' => [ 'source' => [ - 'path' => $this->getTestDir() . '/*.download_file', + 'path' => $this->getTestDir() . '/*.download_file', 'url' => 'download/files' ], 'class' => '' @@ -156,9 +154,9 @@ public function optionsProvider() */ protected function getTestDir() { - $tmpDir = ini_get('upload_tmp_dir'); - if (!$tmpDir || !is_dir($tmpDir) || !is_writable($tmpDir)) { - $tmpDir = sys_get_temp_dir(); + $tmpDir = sys_get_temp_dir(); + if (!($tmpDir && is_dir($tmpDir) && is_writable($tmpDir))) { + $this->markTestSkipped(sprintf('This test requires access on create dir in temp folder "%s"', $tmpDir)); } return $tmpDir . DIRECTORY_SEPARATOR . 'oro_download_dir'; @@ -166,16 +164,18 @@ protected function getTestDir() /** * Remove test dir + * + * @param string $dir */ - protected function removeTestDir() + protected function removeTestDir($dir) { - if (is_dir($this->testDir)) { - $files = new \RecursiveDirectoryIterator($this->testDir, \RecursiveDirectoryIterator::SKIP_DOTS); + if (is_dir($dir)) { + $files = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS); foreach ($files as $fileInfo) { unlink($fileInfo->getRealPath()); } - rmdir($this->testDir); + rmdir($dir); } } } From 5c61154eadcdf181be9b0b63d61e5ec1bc1c56c8 Mon Sep 17 00:00:00 2001 From: Vova Soroka Date: Thu, 12 Feb 2015 17:30:23 +0200 Subject: [PATCH 11/11] BAP-7313: Rede Bebe - e-mail connection. Fix issue when the next batch is not loaded after invalid message --- .../ImapBundle/Manager/ImapEmailIterator.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Oro/Bundle/ImapBundle/Manager/ImapEmailIterator.php b/src/Oro/Bundle/ImapBundle/Manager/ImapEmailIterator.php index 6fb57002835..dbcdafd037f 100644 --- a/src/Oro/Bundle/ImapBundle/Manager/ImapEmailIterator.php +++ b/src/Oro/Bundle/ImapBundle/Manager/ImapEmailIterator.php @@ -123,6 +123,12 @@ public function next() // call the underlying iterator to make sure a batch is loaded // actually $this->batch is initialized at this moment $this->iterator->next(); + + // skip invalid messages (they are not added to $this->batch) + while (!isset($this->batch[$this->iterationPos]) && $this->iterator->valid()) { + $this->iterationPos++; + $this->iterator->next(); + } } /** @@ -138,11 +144,6 @@ public function key() */ public function valid() { - // enforce next batch loading if all entries in batch were invalid - while (empty($this->batch) && $this->iterator->valid()) { - $this->iterator->next(); - } - return isset($this->batch[$this->iterationPos]); } @@ -166,23 +167,24 @@ protected function handleBatchLoaded($batch) { $this->batch = []; - // enforce increment keys - $added = 0; + $counter = 0; foreach ($batch as $key => $val) { try { $email = $this->manager->convertToEmail($val); } catch (\Exception $e) { if (null !== $this->onConvertError) { call_user_func($this->onConvertError, $e); - - continue; + $email = null; + } else { + throw $e; } - - throw $e; } - $this->batch[$this->iterationPos + $added] = $email; - $added++; + // do not add invalid messages to $this->batch + if ($email !== null) { + $this->batch[$this->iterationPos + $counter] = $email; + } + $counter++; } } }