Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into MAGETWO-36298
Browse files Browse the repository at this point in the history
  • Loading branch information
Susan Wright committed Apr 23, 2015
2 parents 475e786 + 4cec5b0 commit ff24033
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 15 deletions.
3 changes: 0 additions & 3 deletions app/code/Magento/Integration/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)->setComment(
'OAuth Nonce'
)->setOption(
'type',
'MyISAM'
);
$installer->getConnection()->createTable($table);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public function testGetList()
->setValue($cart->getSubtotal())
->create();

$yesterdayDate = (new \DateTime())->sub(new \DateInterval('P1D'))->format('Y-m-d');
$tomorrowDate = (new \DateTime())->add(new \DateInterval('P1D'))->format('Y-m-d');
$yesterdayDate = (new \DateTime($cart->getCreatedAt()))->sub(new \DateInterval('P1D'))->format('Y-m-d');
$tomorrowDate = (new \DateTime($cart->getCreatedAt()))->add(new \DateInterval('P1D'))->format('Y-m-d');
$minCreatedAtFilter = $this->filterBuilder->setField('created_at')
->setConditionType('gteq')
->setValue($yesterdayDate)
Expand Down
9 changes: 7 additions & 2 deletions lib/internal/Magento/Framework/Phrase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Zend\Stdlib\JsonSerializable;
use Magento\Framework\Phrase\RendererInterface;
use Magento\Framework\Phrase\Renderer\Placeholder;

class Phrase implements JsonSerializable
{
Expand Down Expand Up @@ -51,7 +52,11 @@ public static function setRenderer(RendererInterface $renderer)
*/
public static function getRenderer()
{
return self::$renderer;
if (self::$renderer) {
return self::$renderer;
} else {
self::$renderer = new \Magento\Framework\Phrase\Renderer\Placeholder();
}
}

/**
Expand Down Expand Up @@ -93,7 +98,7 @@ public function getArguments()
*/
public function render()
{
return self::$renderer ? self::$renderer->render([$this->text], $this->arguments) : $this->text;
return self::getRenderer() ? self::getRenderer()->render([$this->text], $this->arguments) : $this->text;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/Magento/Framework/Phrase/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Phase
# Phrase

Class *\Magento\Framework\Phrase* calls renderer to make the translation of the text. **Phase** provides *RedererInterface* and a few renderers to support different kinds of needs of translation of the text. Here are list of renderers in this library:
Class *\Magento\Framework\Phrase* calls renderer to make the translation of the text. **Phrase** provides *RendererInterface* and a few renderers to support different kinds of needs of translation of the text. Here are list of renderers in this library:

* Placeholder render - it replaces placeholders with parameters for substitution. It is the default render if none is set for the Phrase.
* Translate render - it is a base renderer that implements text translations.
* Inline render - it adds inline translate part to text translation and returns the strings by a template.
* Placeholder render - it replaces placeholders with parameters for substitution.
* Composite render - it can have several renderers, calls each renderer for processing the text. Array of renderer class names pass into composite render constructor as a parameter.
53 changes: 48 additions & 5 deletions lib/internal/Magento/Framework/Test/Unit/PhraseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class PhraseTest extends \PHPUnit_Framework_TestCase
*/
protected $rendererMock;

/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
protected $objectManager;

/**
* SetUp method
*
Expand All @@ -29,6 +34,7 @@ protected function setUp()
$this->defaultRenderer = Phrase::getRenderer();
$this->rendererMock = $this->getMockBuilder('Magento\Framework\Phrase\RendererInterface')
->getMock();
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
}

/**
Expand All @@ -51,7 +57,10 @@ public function testRendering()
$text = 'some text';
$arguments = ['arg1', 'arg2'];
$result = 'rendered text';
$phrase = new Phrase($text, $arguments);
$phrase = $this->objectManager->getObject('Magento\Framework\Phrase', [
'text' => $text,
'arguments' => $arguments,
]);
Phrase::setRenderer($this->rendererMock);

$this->rendererMock->expects($this->once())
Expand All @@ -72,7 +81,9 @@ public function testDefersRendering()
$this->rendererMock->expects($this->never())
->method('render');

new Phrase('some text');
$this->objectManager->getObject('Magento\Framework\Phrase', [
'text' => 'some text',
]);
}

/**
Expand All @@ -85,7 +96,10 @@ public function testThatToStringIsAliasToRender()
$text = 'some text';
$arguments = ['arg1', 'arg2'];
$result = 'rendered text';
$phrase = new Phrase($text, $arguments);
$phrase = $this->objectManager->getObject('Magento\Framework\Phrase', [
'text' => $text,
'arguments' => $arguments,
]);
Phrase::setRenderer($this->rendererMock);

$this->rendererMock->expects($this->once())
Expand All @@ -105,6 +119,9 @@ public function testGetText()
{
$text = 'some text';
$phrase = new Phrase($text);
$phrase = $this->objectManager->getObject('Magento\Framework\Phrase', [
'text' => $text,
]);

$this->assertEquals($text, $phrase->getText());
}
Expand All @@ -118,10 +135,36 @@ public function testGetArguments()
{
$text = 'some text';
$arguments = ['arg1', 'arg2'];
$phrase1 = new Phrase($text);
$phrase2 = new Phrase($text, $arguments);
$phrase1 = $this->objectManager->getObject('Magento\Framework\Phrase', [
'text' => $text,
]);
$phrase2 = $this->objectManager->getObject('Magento\Framework\Phrase', [
'text' => $text,
'arguments' => $arguments,
]);

$this->assertEquals([], $phrase1->getArguments());
$this->assertEquals($arguments, $phrase2->getArguments());
}

/**
* Test default rendering
*
* @return void
*/
public function testDefaultRendering()
{
$text = 'parameter1 is replaced by %1 parameter2 is replaced by %2';
$arguments = ['arg1', 'arg2'];
$result = 'parameter1 is replaced by arg1 parameter2 is replaced by arg2';
$phrase = $this->objectManager->getObject('Magento\Framework\Phrase', [
'text' => $text,
'arguments' => $arguments,
]);

$this->assertEquals($text, $phrase->getText());
$this->assertEquals($arguments, $phrase->getArguments());
$this->assertTrue($phrase->getRenderer() instanceof \Magento\Framework\Phrase\Renderer\Placeholder);
$this->assertEquals($result, $phrase->render());
}
}

0 comments on commit ff24033

Please sign in to comment.