/**
  * @covers ::preRender
  */
 public function testPreRender()
 {
     $payment_status_created = mt_rand();
     $payment_status = $this->getMock(PaymentStatusInterface::class);
     $payment_status->expects($this->atLeastOnce())->method('getCreated')->willReturn($payment_status_created);
     $this->dateFormatter->expects($this->once())->method('format')->with($payment_status_created);
     $element = array('#payment_statuses' => [$payment_status]);
     $build = $this->sut->preRender($element);
     $this->assertSame('table', $build['table']['#type']);
 }
 /**
  * @covers ::buildRow
  *
  * @dataProvider providerTestBuildRow
  *
  * @depends testBuildOperations
  */
 function testBuildRow($payment_currency_exists)
 {
     $payment_changed_time = time();
     $payment_changed_time_formatted = $this->randomMachineName();
     $payment_currency_code = $this->randomMachineName();
     $payment_amount = mt_rand();
     $payment_amount_formatted = $this->randomMachineName();
     $payment_status_definition = array('label' => $this->randomMachineName());
     $payment_status = $this->getMock(PaymentStatusInterface::class);
     $payment_status->expects($this->any())->method('getPluginDefinition')->willReturn($payment_status_definition);
     $owner = $this->getMock(UserInterface::class);
     $payment_method_label = $this->randomMachineName();
     $payment_method_definition = ['label' => $payment_method_label];
     $payment_method = $this->getMock(PaymentMethodInterface::class);
     $payment_method->expects($this->atLeastOnce())->method('getPluginDefinition')->willReturn($payment_method_definition);
     $payment = $this->getMock(PaymentInterface::class);
     $payment->expects($this->any())->method('getAmount')->willReturn($payment_amount);
     $payment->expects($this->any())->method('getChangedTime')->willReturn($payment_changed_time);
     $payment->expects($this->any())->method('getCurrencyCode')->willReturn($payment_currency_code);
     $payment->expects($this->any())->method('getOwner')->willReturn($owner);
     $payment->expects($this->any())->method('getPaymentMethod')->willReturn($payment_method);
     $payment->expects($this->any())->method('getPaymentStatus')->willReturn($payment_status);
     $currency = $this->getMock(CurrencyInterface::class);
     $currency->expects($this->once())->method('formatAmount')->with($payment_amount)->willReturn($payment_amount_formatted);
     $map = array(array($payment_currency_code, $payment_currency_exists ? $currency : NULL), array('XXX', $payment_currency_exists ? NULL : $currency));
     $this->currencyStorage->expects($this->atLeastOnce())->method('load')->willReturnMap($map);
     $this->dateFormatter->expects($this->once())->method('format')->with($payment_changed_time)->willReturn($payment_changed_time_formatted);
     $this->moduleHandler->expects($this->any())->method('invokeAll')->willReturn([]);
     $build = $this->sut->buildRow($payment);
     unset($build['data']['operations']['data']['#attached']);
     $expected_build = array('data' => array('updated' => $payment_changed_time_formatted, 'status' => $payment_status_definition['label'], 'amount' => $payment_amount_formatted, 'payment_method' => $payment_method_label, 'owner' => array('data' => array('#theme' => 'username', '#account' => $owner)), 'operations' => array('data' => array('#type' => 'operations', '#links' => []))));
     $this->assertSame($expected_build, $build);
 }
Beispiel #3
0
 /**
  * Tests the formatTimeDiffSince method.
  *
  * @covers ::formatTimeDiffSince
  */
 public function testFormatTimeDiffSince()
 {
     $expected = '1 second';
     $timestamp = $this->createTimestamp('2013-12-11 10:09:07');
     $request_time = $this->createTimestamp('2013-12-11 10:09:08');
     $options = array();
     // Mocks the formatDiff function of the dateformatter object.
     $this->dateFormatterStub->expects($this->any())->method('formatDiff')->with($request_time, $timestamp, $options)->will($this->returnValue($expected));
     $request = Request::createFromGlobals();
     $request->server->set('REQUEST_TIME', $request_time);
     // Mocks a the request stack getting the current request.
     $this->requestStack->expects($this->any())->method('getCurrentRequest')->willReturn($request);
     $this->assertEquals($expected, $this->dateFormatterStub->formatTimeDiffUntil($timestamp, $options));
 }