You are here

class CartLinksRegexpTest in Ubercart 8.4

@coversDefaultClass \Drupal\uc_cart_links\CartLinksValidator

@group ubercart

Hierarchy

Expanded class hierarchy of CartLinksRegexpTest

File

uc_cart_links/tests/src/Unit/CartLinksRegexpTest.php, line 14

Namespace

Drupal\Tests\uc_cart_links\Unit
View source
class CartLinksRegexpTest extends UnitTestCase {

  /**
   * The Drupal service container.
   *
   * @var \Drupal\Core\DependencyInjection\Container
   */
  protected $container;

  /**
   * The mocked expression manager object.
   *
   * @var \Drupal\uc_cart_links\CartLinksValidatorInterface
   */
  protected $cartLinksValidator;

  /**
   * The messenger service.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $container = new ContainerBuilder();
    $this->messenger = new TestMessenger();
    $this->cartLinksValidator = new CartLinksValidator($this->messenger);
    $container
      ->set('uc_cart_links.validator', $this->cartLinksValidator);
    $container
      ->set('messenger', $this->messenger);
    \Drupal::setContainer($container);
    $this->container = $container;
  }

  /**
   * Tests that isValidSyntax() throws an exception when the status is locked.
   *
   * @covers ::isValidSyntax
   */
  public function testIsValidSyntax() {
    $links = [
      '/cart/add/p23',
      '/cart/add/p23_q5',
      '/cart/add/p23_q5-p18_q2',
      '/cart/add/e-p23_q5-m15-m32',
      '/cart/add/e-p23_q5_a12o5_a19o9_a1oA%20Text%20String_s-ispecialoffer-m77?destination=/cart/checkout',
    ];

    // Test valid links.
    foreach ($links as $link) {
      $this
        ->assertTrue($this->cartLinksValidator
        ->isValidSyntax($link, FALSE));
    }
    $links = [
      '/cart/add/q23',
    ];

    // Test invalid links.
    foreach ($links as $link) {
      $this
        ->assertFalse($this->cartLinksValidator
        ->isValidSyntax($link, FALSE));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CartLinksRegexpTest::$cartLinksValidator protected property The mocked expression manager object.
CartLinksRegexpTest::$container protected property The Drupal service container.
CartLinksRegexpTest::$messenger protected property The messenger service.
CartLinksRegexpTest::setUp protected function Overrides UnitTestCase::setUp
CartLinksRegexpTest::testIsValidSyntax public function Tests that isValidSyntax() throws an exception when the status is locked.
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.