class CartLinksRegexpTest in Ubercart 8.4
@coversDefaultClass \Drupal\uc_cart_links\CartLinksValidator
@group ubercart
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\uc_cart_links\Unit\CartLinksRegexpTest
 
 
Expanded class hierarchy of CartLinksRegexpTest
File
- uc_cart_links/
tests/ src/ Unit/ CartLinksRegexpTest.php, line 14  
Namespace
Drupal\Tests\uc_cart_links\UnitView 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
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            CartLinksRegexpTest:: | 
                  protected | property | The mocked expression manager object. | |
| 
            CartLinksRegexpTest:: | 
                  protected | property | The Drupal service container. | |
| 
            CartLinksRegexpTest:: | 
                  protected | property | The messenger service. | |
| 
            CartLinksRegexpTest:: | 
                  protected | function | 
            Overrides UnitTestCase:: | 
                  |
| 
            CartLinksRegexpTest:: | 
                  public | function | Tests that isValidSyntax() throws an exception when the status is locked. | |
| 
            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. |