You are here

class DmsConverterTest in Geofield 8

@coversDefaultClass \Drupal\geofield\DmsConverter @group geofield

Hierarchy

Expanded class hierarchy of DmsConverterTest

File

tests/src/Unit/DmsConverterTest.php, line 13

Namespace

Drupal\Tests\geofield\Unit
View source
class DmsConverterTest extends UnitTestCase {

  /**
   * @covers ::dmsToDecimal
   * @covers ::decimalToDms
   *
   * @dataProvider dataProvider
   */
  public function testConverter(DmsPoint $dms, $decimal) {
    $result = DmsConverter::dmsToDecimal($dms);
    $this
      ->assertEquals($decimal, $result);
    $result = DmsConverter::decimalToDms($decimal[0], $decimal[1]);
    $this
      ->assertEquals($dms, $result);
  }

  /**
   * Data provider for testConverter.
   *
   * @return array
   *   A list of equivalent DMS/Decimal coordinates.
   */
  public function dataProvider() {
    return [
      'Simple' => [
        new DmsPoint([
          'orientation' => 'E',
          'degrees' => 40,
          'minutes' => 0,
          'seconds' => 0,
        ], [
          'orientation' => 'N',
          'degrees' => 9,
          'minutes' => 0,
          'seconds' => 0,
        ]),
        [
          40,
          9,
        ],
      ],
      'Negative' => [
        new DmsPoint([
          'orientation' => 'W',
          'degrees' => 40,
          'minutes' => 0,
          'seconds' => 0,
        ], [
          'orientation' => 'S',
          'degrees' => 9,
          'minutes' => 0,
          'seconds' => 0,
        ]),
        [
          -40,
          -9,
        ],
      ],
      'Decimal' => [
        new DmsPoint([
          'orientation' => 'W',
          'degrees' => 3,
          'minutes' => 3,
          'seconds' => 3,
        ], [
          'orientation' => 'S',
          'degrees' => 2,
          'minutes' => 2,
          'seconds' => 2,
        ]),
        [
          -3.0508333333333333,
          -2.033888888888889,
        ],
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DmsConverterTest::dataProvider public function Data provider for testConverter.
DmsConverterTest::testConverter public function @covers ::dmsToDecimal @covers ::decimalToDms
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340