DomainTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cookie\Model\Config\Backend;
  7. use Magento\Framework\Exception\LocalizedException;
  8. /**
  9. * Test \Magento\Cookie\Model\Config\Backend\Domain
  10. *
  11. * @magentoAppArea adminhtml
  12. */
  13. class DomainTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @param string $value
  17. * @param string $exceptionMessage
  18. * @magentoDbIsolation enabled
  19. * @dataProvider beforeSaveDataProvider
  20. */
  21. public function testBeforeSave($value, $exceptionMessage = null)
  22. {
  23. /** @var $domain \Magento\Cookie\Model\Config\Backend\Domain */
  24. $domain = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  25. \Magento\Cookie\Model\Config\Backend\Domain::class
  26. );
  27. $domain->setValue($value);
  28. $domain->setPath('path');
  29. try {
  30. $domain->save();
  31. if ($exceptionMessage) {
  32. $this->fail('Failed to throw exception');
  33. } else {
  34. $this->assertNotNull($domain->getId());
  35. }
  36. } catch (LocalizedException $e) {
  37. $this->assertContains('Invalid domain name: ', $e->getMessage());
  38. $this->assertEquals($exceptionMessage, $e->getMessage());
  39. $this->assertNull($domain->getId());
  40. }
  41. }
  42. /**
  43. * @return array
  44. */
  45. public function beforeSaveDataProvider()
  46. {
  47. return [
  48. 'not string' => [['array'], 'Invalid domain name: must be a string'],
  49. 'invalid hostname' => [
  50. 'http://',
  51. 'Invalid domain name: The input does not match the expected structure for a DNS hostname; '
  52. . 'The input does not appear to be a valid URI hostname; '
  53. . 'The input does not appear to be a valid local network name',
  54. ],
  55. 'valid hostname' => ['hostname.com'],
  56. 'empty string' => [''],
  57. ];
  58. }
  59. }