class ExtraFieldFormManagerTest in Extra Field 8.2
@coversDefaultClass \Drupal\extra_field\Plugin\ExtraFieldFormManager
@group extra_field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait- class \Drupal\Tests\extra_field\Unit\ExtraFieldFormManagerTest
 
Expanded class hierarchy of ExtraFieldFormManagerTest
File
- tests/src/ Unit/ ExtraFieldFormManagerTest.php, line 12 
Namespace
Drupal\Tests\extra_field\UnitView source
class ExtraFieldFormManagerTest extends UnitTestCase {
  /**
   * The plugin manager under test.
   *
   * @var \Drupal\extra_field\Plugin\ExtraFieldFormManagerInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $formManager;
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->formManager = $this
      ->getMockBuilder('Drupal\\extra_field\\Plugin\\ExtraFieldFormManager')
      ->disableOriginalConstructor()
      ->setMethods([
      'getDefinitions',
      'allEntityBundles',
    ])
      ->getMock();
  }
  /**
   * Prepare ::getDefinitions to return the right values.
   *
   * @param array $definitions
   *   The plugin definitions to return.
   */
  protected function prepareDefinitions(array $definitions) {
    $this->formManager
      ->expects($this
      ->any())
      ->method('getDefinitions')
      ->will($this
      ->returnValue($definitions));
  }
  /**
   * Prepare ::allEntityBundles to return the right values.
   *
   * @param array $bundlesMap
   *   Array of bundle names.
   */
  protected function prepareEntityBundles(array $bundlesMap) {
    $this->formManager
      ->expects($this
      ->any())
      ->method('allEntityBundles')
      ->will($this
      ->returnValueMap($bundlesMap));
  }
  /**
   * @covers ::fieldInfo
   *
   * @dataProvider fieldInfoProvider
   *
   * @param array $definitions
   *   Plugin definitions as returned by ::getDefinitions.
   * @param array $bundles
   *   Entity bundles as returned by ::allEntityBundles.
   * @param array $results
   *   Field info as returned by ::fieldInfo.
   */
  public function testFieldInfo(array $definitions, array $bundles, array $results) {
    $this
      ->prepareDefinitions($definitions);
    $this
      ->prepareEntityBundles($bundles);
    $this
      ->assertEquals(count($this->formManager
      ->getDefinitions()), count($definitions));
    $this
      ->assertEquals($this->formManager
      ->fieldInfo(), $results);
  }
  /**
   * Data provider for testFieldInfo().
   */
  public function fieldInfoProvider() {
    $info[] = [
      // Definitions.
      [
        'test' => [
          'id' => 'test',
          'bundles' => [
            'node.article',
          ],
          'label' => 'test form node article',
          'description' => 'test description form node article',
          'weight' => 0,
          'visible' => FALSE,
        ],
      ],
      // Bundles.
      [],
      // Results.
      [
        'node' => [
          'article' => [
            'form' => [
              'extra_field_test' => [
                'label' => 'test form node article',
                'description' => 'test description form node article',
                'weight' => 0,
                'visible' => FALSE,
              ],
            ],
          ],
        ],
      ],
    ];
    $info[] = [
      // Definitions.
      [
        'test' => [
          'id' => 'test',
          'bundles' => [
            'node.article',
          ],
          'label' => 'test form node article',
          'description' => 'test description form node article',
          'weight' => 88,
          'visible' => TRUE,
        ],
      ],
      // Bundles.
      [],
      // Results.
      [
        'node' => [
          'article' => [
            'form' => [
              'extra_field_test' => [
                'label' => 'test form node article',
                'description' => 'test description form node article',
                'weight' => 88,
                'visible' => TRUE,
              ],
            ],
          ],
        ],
      ],
    ];
    $info[] = [
      // Definitions.
      [
        'test1' => [
          'id' => 'test1',
          'bundles' => [
            'node.*',
            'come.*',
          ],
          'label' => 'test form 1',
          'description' => 'test description form 1',
          'weight' => 0,
          'visible' => FALSE,
        ],
        'test2' => [
          'id' => 'test2',
          'bundles' => [
            'node.article',
          ],
          'label' => 'test form 2',
          'description' => 'test description form 2',
          'weight' => 2,
          'visible' => TRUE,
        ],
      ],
      // Bundles.
      [
        [
          'node',
          [
            'article',
            'story',
            'blog',
          ],
        ],
        [
          'come',
          [
            'rain',
            'shine',
          ],
        ],
      ],
      // Results.
      [
        'node' => [
          'article' => [
            'form' => [
              'extra_field_test1' => [
                'label' => 'test form 1',
                'description' => 'test description form 1',
                'weight' => 0,
                'visible' => FALSE,
              ],
              'extra_field_test2' => [
                'label' => 'test form 2',
                'description' => 'test description form 2',
                'weight' => 2,
                'visible' => TRUE,
              ],
            ],
          ],
          'story' => [
            'form' => [
              'extra_field_test1' => [
                'label' => 'test form 1',
                'description' => 'test description form 1',
                'weight' => 0,
                'visible' => FALSE,
              ],
            ],
          ],
          'blog' => [
            'form' => [
              'extra_field_test1' => [
                'label' => 'test form 1',
                'description' => 'test description form 1',
                'weight' => 0,
                'visible' => FALSE,
              ],
            ],
          ],
        ],
        'come' => [
          'rain' => [
            'form' => [
              'extra_field_test1' => [
                'label' => 'test form 1',
                'description' => 'test description form 1',
                'weight' => 0,
                'visible' => FALSE,
              ],
            ],
          ],
          'shine' => [
            'form' => [
              'extra_field_test1' => [
                'label' => 'test form 1',
                'description' => 'test description form 1',
                'weight' => 0,
                'visible' => FALSE,
              ],
            ],
          ],
        ],
      ],
    ];
    return $info;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| ExtraFieldFormManagerTest:: | protected | property | The plugin manager under test. | |
| ExtraFieldFormManagerTest:: | public | function | Data provider for testFieldInfo(). | |
| ExtraFieldFormManagerTest:: | protected | function | Prepare ::getDefinitions to return the right values. | |
| ExtraFieldFormManagerTest:: | protected | function | Prepare ::allEntityBundles to return the right values. | |
| ExtraFieldFormManagerTest:: | protected | function | Overrides UnitTestCase:: | |
| ExtraFieldFormManagerTest:: | public | function | @covers ::fieldInfo | |
| PhpunitCompatibilityTrait:: | public | function | Returns a mock object for the specified class using the available method. | |
| PhpunitCompatibilityTrait:: | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| UnitTestCase:: | protected | property | The random generator. | |
| UnitTestCase:: | protected | property | The app root. | 1 | 
| UnitTestCase:: | protected | function | Asserts if two arrays are equal by sorting them first. | |
| UnitTestCase:: | protected | function | Mocks a block with a block plugin. | 1 | 
| UnitTestCase:: | protected | function | Returns a stub class resolver. | |
| UnitTestCase:: | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase:: | public | function | Returns a stub config storage that returns the supplied configuration. | |
| UnitTestCase:: | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase:: | protected | function | Gets the random generator for the utility methods. | |
| UnitTestCase:: | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase:: | public | function | Generates a unique random string containing letters and numbers. | 
