Skip to content

Commit

Permalink
Remove duplicate documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
haringsrob committed Sep 9, 2017
1 parent 958f297 commit 102f6a1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane;

use Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;

/**
Expand All @@ -23,7 +25,7 @@ class CompletionMessage extends CheckoutPaneBase {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, \Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface $checkout_flow, \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, CheckoutFlowInterface $checkout_flow, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $checkout_flow, $entity_type_manager);
$this->completionMessags = new CompletionMessages();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\TranslatableInterface;

/**
* Acts as a container to collect all completion messages.
Expand All @@ -13,7 +12,7 @@
class CompletionMessages implements \Iterator, \Countable {

/**
* @var \Drupal\Core\TypedData\TranslatableInterface[]
* @var \Drupal\Core\StringTranslation\TranslatableMarkup[]
*/
private $messages;

Expand All @@ -30,81 +29,58 @@ public function __construct() {
}

/**
* Return the current element
* Adds a message to the array.
*
* @param \Drupal\Core\StringTranslation\TranslatableMarkup $message
* The message to add.
*/
public function addMessage(TranslatableMarkup $message) {
$this->messages[] = $message;
}

/**
* Gets the current message.
*
* @link http://php.net/manual/en/iterator.current.php
* @return mixed Can return any type.
* @since 5.0.0
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The current message.
*/
public function current() {
return $this->messages[$this->position];
}

/**
* Move forward to next element
*
* @link http://php.net/manual/en/iterator.next.php
* @return void Any returned value is ignored.
* @since 5.0.0
* {@inheritdoc}
*/
public function next() {
++$this->position;
}

/**
* Return the key of the current element
*
* @link http://php.net/manual/en/iterator.key.php
* @return mixed scalar on success, or null on failure.
* @since 5.0.0
* {@inheritdoc}
*/
public function key() {
return $this->position;
}

/**
* Checks if current position is valid
*
* @link http://php.net/manual/en/iterator.valid.php
* @return boolean The return value will be casted to boolean and then
* evaluated. Returns true on success or false on failure.
* @since 5.0.0
* {@inheritdoc}
*/
public function valid() {
return isset($this->messages[$this->position]);
}

/**
* Rewind the Iterator to the first element
*
* @link http://php.net/manual/en/iterator.rewind.php
* @return void Any returned value is ignored.
* @since 5.0.0
* {@inheritdoc}
*/
public function rewind() {
$this->position = 0;
}

/**
* Adds a message to the array.
*
* @param \Drupal\Core\StringTranslation\TranslatableMarkup $message
*/
public function addMessage(TranslatableMarkup $message) {
$this->messages[] = $message;
}

/**
* Count elements of an object
*
* @link http://php.net/manual/en/countable.count.php
* @return int The custom count as an integer.
* </p>
* <p>
* The return value is cast to an integer.
* @since 5.1.0
* {@inheritdoc}
*/
public function count() {
return count($this->messages);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#}
<div class="checkout-complete">
{% for message in completion_messages %}
{{ message }}
{{ message }} <br/>
{% endfor %}

{{ 'Your order number is @number.'|t({'@number': order_entity.getOrderNumber}) }} <br>
Expand Down
21 changes: 13 additions & 8 deletions modules/checkout/tests/src/Kernel/CompletionMessagesTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: robharings
* Date: 09/09/2017
* Time: 13:31
*/

namespace Drupal\Tests\commerce_checkout\Kernel;

Expand All @@ -15,26 +9,37 @@
* Tests the completion messages class.
*
* @covers \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CompletionMessages
*
* @group commerce
*/
class CompletionMessagesTest extends CommerceKernelTestBase {

/**
* @var CompletionMessages
* @var \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CompletionMessages
*/
private $completionMessages;

/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->completionMessages = new CompletionMessages();
}

/**
* Tests add message method.
*/
public function testAddMessage() {
$this->completionMessages->addMessage(t('Message 1'));
$this->completionMessages->addMessage(t('Message 2'));

$this->assertCount(2, $this->completionMessages);
}

/**
* Tests the messages iterator.
*/
public function testMessagesIterator() {
$this->completionMessages->addMessage(t('Message 1'));
$this->completionMessages->addMessage(t('Message 2'));
Expand All @@ -44,4 +49,4 @@ public function testMessagesIterator() {
$this->assertEquals('Message 2', $this->completionMessages->current()->render());
}

}
}

0 comments on commit 102f6a1

Please sign in to comment.