/** * Tests installation and uninstallation. */ function testInstallationAndUninstallation() { /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */ $module_installer = \Drupal::service('module_installer'); $module_handler = \Drupal::moduleHandler(); $this->assertTrue(Currency::load('XXX') instanceof CurrencyInterface); $this->assertTrue(CurrencyLocale::load('en_US') instanceof CurrencyLocaleInterface); $module_installer->uninstall(array('currency')); $this->assertFalse($module_handler->moduleExists('currency')); }
/** * @covers ::toArray */ public function testToArray() { $entity_type = $this->getMock(EntityTypeInterface::class); $entity_type->expects($this->atLeastOnce())->method('getKey')->with('label')->willReturn('label'); $this->entityManager->expects($this->atLeastOnce())->method('getDefinition')->with($this->entityTypeId)->willReturn($entity_type); $alternative_signs = [$this->randomMachineName(), $this->randomMachineName(), $this->randomMachineName()]; $currency_code = $this->randomMachineName(); $currency_number = mt_rand(); $exchange_rates = [$this->randomMachineName() => mt_rand(), $this->randomMachineName() => mt_rand(), $this->randomMachineName() => mt_rand()]; $rounding_step = mt_rand(); $sign = $this->randomMachineName(); $subunits = mt_rand(); $status = TRUE; $label = $this->randomMachineName(); $usage_start_a = mt_rand(); $usage_end_a = mt_rand(); $usage_country_code_a = $this->randomMachineName(); $usage_start_b = mt_rand(); $usage_end_b = mt_rand(); $usage_country_code_b = $this->randomMachineName(); $usage_start_c = mt_rand(); $usage_end_c = mt_rand(); $usage_country_code_c = $this->randomMachineName(); /** @var \Drupal\currency\Usage[] $usages */ $usages = [(new Usage())->setStart($usage_start_a)->setEnd($usage_end_a)->setCountryCode($usage_country_code_a), (new Usage())->setStart($usage_start_b)->setEnd($usage_end_b)->setCountryCode($usage_country_code_b), (new Usage())->setStart($usage_start_c)->setEnd($usage_end_c)->setCountryCode($usage_country_code_c)]; $expected_array['alternativeSigns'] = $alternative_signs; $expected_array['currencyCode'] = $currency_code; $expected_array['currencyNumber'] = $currency_number; $expected_array['label'] = $label; $expected_array['roundingStep'] = $rounding_step; $expected_array['sign'] = $sign; $expected_array['subunits'] = $subunits; $expected_array['status'] = $status; $expected_array['usages'] = [['start' => $usage_start_a, 'end' => $usage_end_a, 'countryCode' => $usage_country_code_a], ['start' => $usage_start_b, 'end' => $usage_end_b, 'countryCode' => $usage_country_code_b], ['start' => $usage_start_c, 'end' => $usage_end_c, 'countryCode' => $usage_country_code_c]]; $this->sut->setAlternativeSigns($expected_array['alternativeSigns']); $this->sut->setLabel($label); $this->sut->setUsages($usages); $this->sut->setSubunits($subunits); $this->sut->setRoundingStep($rounding_step); $this->sut->setSign($sign); $this->sut->setStatus($status); $this->sut->setCurrencyCode($currency_code); $this->sut->setCurrencyNumber($currency_number); $array = $this->sut->toArray(); $this->assertArrayHasKey('uuid', $array); unset($array['uuid']); $this->assertEquals($expected_array, $array); }