You are here

public function TestMapper::testGetMaxValues in Feeds Paragraphs 8

@covers ::getMaxValues

File

tests/src/Unit/TestMapper.php, line 210

Class

TestMapper
@group Feeds Paragraphs @coversDefaultClass \Drupal\feeds_para_mapper\Mapper

Namespace

Drupal\Tests\feeds_para_mapper\Unit

Code

public function testGetMaxValues() {
  $field = $this->fieldHelper
    ->getBundleFields('bundle_two')[0]
    ->reveal();

  // Cardinality is -1:
  $expected = (int) $field
    ->getFieldStorageDefinition()
    ->getCardinality();
  $max = $this->mapper
    ->getMaxValues($field);
  self::assertSame($expected, $max);
  $max = $this->mapper
    ->getMaxValues($field, array(
    'max_values' => 10,
  ));
  self::assertSame(10, $max);

  // Invalid input should return the field cardinality:
  $max = $this->mapper
    ->getMaxValues($field, array(
    'max_values' => -2,
  ));
  self::assertSame($expected, $max);
  $field
    ->set('cardinality', '2');
  $max = $this->mapper
    ->getMaxValues($field, array(
    'max_values' => -2,
  ));
  self::assertSame(2, $max);
  $max = $this->mapper
    ->getMaxValues($field, array(
    'max_values' => 3,
  ));
  self::assertSame(2, $max);
}