You are here

public function InvoiceTypeTest::testInvoiceType in Commerce Invoice 8.2

@covers ::id @covers ::label @covers ::getNumberPattern @covers ::getNumberPatternId @covers ::setNumberPatternId @covers ::getLogoUrl @covers ::getLogoFile @covers ::setLogo @covers ::getFooterText @covers ::setFooterText @covers ::getDueDays @covers ::setDueDays @covers ::getPaymentTerms @covers ::setPaymentTerms

File

tests/src/Kernel/Entity/InvoiceTypeTest.php, line 35

Class

InvoiceTypeTest
Tests the invoice type entity.

Namespace

Drupal\Tests\commerce_invoice\Kernel\Entity

Code

public function testInvoiceType() {
  $file = File::create([
    'fid' => 1,
    'filename' => 'test.png',
    'filesize' => 100,
    'uri' => 'public://images/test.png',
    'filemime' => 'image/png',
  ]);
  $file
    ->save();
  $file = $this
    ->reloadEntity($file);
  $values = [
    'id' => 'test_id',
    'label' => 'Test label',
    'footerText' => $this
      ->randomString(),
    'paymentTerms' => $this
      ->randomString(),
    'numberPattern' => 'invoice_default',
    'logo' => $file
      ->uuid(),
    'dueDays' => 10,
    'workflow' => 'invoice_default',
  ];
  $invoice_type = InvoiceType::create($values);
  $invoice_type
    ->save();
  $this
    ->assertEquals('test_id', $invoice_type
    ->id());
  $this
    ->assertEquals('Test label', $invoice_type
    ->label());
  $this
    ->assertEquals($values['numberPattern'], $invoice_type
    ->getNumberPatternId());
  $this
    ->assertInstanceOf(NumberPatternInterface::class, $invoice_type
    ->getNumberPattern());
  $invoice_type
    ->setNumberPatternId('test');
  $this
    ->assertEquals('test', $invoice_type
    ->getNumberPatternId());
  $this
    ->assertEquals($file
    ->createFileUrl(FALSE), $invoice_type
    ->getLogoUrl());
  $this
    ->assertEquals($file, $invoice_type
    ->getLogoFile());
  $this
    ->assertEquals($values['footerText'], $invoice_type
    ->getFooterText());
  $invoice_type
    ->setFooterText('Footer text (modified)');
  $this
    ->assertEquals('Footer text (modified)', $invoice_type
    ->getFooterText());
  $this
    ->assertEquals($values['dueDays'], $invoice_type
    ->getDueDays());
  $invoice_type
    ->setDueDays(15);
  $this
    ->assertEquals(15, $invoice_type
    ->getDueDays());
  $this
    ->assertEquals($values['paymentTerms'], $invoice_type
    ->getPaymentTerms());
  $invoice_type
    ->setPaymentTerms('Payment terms (modified)');
  $this
    ->assertEquals('Payment terms (modified)', $invoice_type
    ->getPaymentTerms());
}