{"id":15255651,"url":"https://github.com/previousnext/drupal-test-utils","last_synced_at":"2025-04-11T23:00:24.915Z","repository":{"id":64754440,"uuid":"577950607","full_name":"previousnext/drupal-test-utils","owner":"previousnext","description":"Utility traits for Drupal testing","archived":false,"fork":false,"pushed_at":"2024-07-23T06:05:20.000Z","size":23,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-05T22:28:29.188Z","etag":null,"topics":["drupal"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/previousnext.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-13T22:44:24.000Z","updated_at":"2024-05-21T00:23:00.000Z","dependencies_parsed_at":"2024-07-21T07:15:15.703Z","dependency_job_id":null,"html_url":"https://github.com/previousnext/drupal-test-utils","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fdrupal-test-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fdrupal-test-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fdrupal-test-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/previousnext%2Fdrupal-test-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/previousnext","download_url":"https://codeload.github.com/previousnext/drupal-test-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248012521,"owners_count":21033216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drupal"],"created_at":"2024-09-30T00:06:58.655Z","updated_at":"2025-04-11T23:00:24.888Z","avatar_url":"https://github.com/previousnext.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Drupal Test Utils\n\nUtilities for testing Drupal!\n\n## ConfigTrait\n\nA trait to facilitate overriding config for the duration of a test.\n\n### Usage\n\nAdd the trait to your base class and override the tearDown method.\n\n```php\nuse PNX\\DrupalTestUtils\\Traits\\ConfigTrait;\nuse weitzman\\DrupalTestTraits\\ExistingSiteBase;\n\nabstract class MyBaseClass extends ExistingSiteBase {\n\n  /**\n   * {@inheritdoc}\n   */\n  protected function tearDown(): void {\n    $this-\u003esetConfigValues($this-\u003eoriginalConfiguration, FALSE);\n    parent::tearDown();\n  }\n\n}\n```\n\nIn a test case, call `$this-\u003esetConfigValues`:\n\n```php\n$this-\u003esetConfigValues([\n  'system.logging' =\u003e [\n    'error_level' =\u003e \\ERROR_REPORTING_DISPLAY_VERBOSE,\n  ],\n]);\n```\n\n## EntityLoadTrait\n\nA trait to assist with loading entities in tests.\n\n### Usage\n\nLoad one node with the title \"Hello, World\":\n\n```php\n$node = $this-\u003eloadEntityByProperty('node', ['title' =\u003e 'Hello, World']);\n```\n\nLoad all article nodes:\n\n```php\n$nodes = $this-\u003eloadEntityByProperty('node', ['type' =\u003e 'article'], FALSE);\n```\n\nGet the last created node. Useful for asserting on entities created via the UI:\n\n```php\n$node = $this-\u003egetLastCreatedEntity('node');\n```\n\n## ExpectsCacheableResponseTrait\n\nA trait to add Dynamic Page Cache cacheability testing to every request in your Functional tests.\n\n### Usage\n\nOnce your trait is added to your test base class, you can check cachability by overriding the `drupalGet` function.\n\n```php\n/**\n * {@inheritdoc}\n */\nprotected function drupalGet($path, array $options = [], array $headers = []): string {\n  $response = parent::drupalGet($path, $options, $headers);\n  $this-\u003edetectUncacheableResponse($path, $options);\n  return $response;\n}\n```\n\n### Marking paths as uncacheable\n\nThere are some paths that are always uncacheable (i.e pages with forms like node/add). These paths can marked as uncacheable\nby adding the `$uncacheableDynamicPagePatterns` property to your tests. You can add a common set of these to your test base\nand add more specific paths in indivdual tests as these patterns will be gathered up the class hierarchy at run time.\n\nPatterns are regular expressions matched with `preg_match`\n\nE.g\n```php\n protected static array $uncacheableDynamicPagePatterns = [\n   '/user/login',\n   '/big_pipe/no-js',\n   '/batch',\n   '/node/add/.*',\n ];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreviousnext%2Fdrupal-test-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpreviousnext%2Fdrupal-test-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreviousnext%2Fdrupal-test-utils/lists"}