District Core Developer DocsDistrict Core Developer Docs
Developers
Boilerplate
Modules
Bitbucket
Developers
Boilerplate
Modules
Bitbucket
  • Modules

    • ABN
    • ActivityLog
    • AnalyticsApi
    • ApiConnector
    • BlockApi
    • CategoryApi
    • CloneApi
    • CommentApi
    • ContentApi
    • Core
    • Documents
    • EmbedApi
    • Event
    • ExportApi
    • FeatureApi
    • FormApi
    • GTM
    • GalleryApi
    • HelpApi
    • Hotspot
    • IdeaSurvey
    • ImportApi
    • InteractionsApi
    • Intercom
    • MailApi
    • MapApi
    • MapSurvey
    • MediaApi
    • MenuApi
    • MetaTagApi
    • NlpApi
    • NotificationApi
    • Page
    • ParentableContent
    • PaymentApi
    • PermissionsApi
    • Postcode
    • ReCaptcha
    • Redirects
    • Renderer
    • ReportApi
    • RestrictionApi
    • RevisionApi
    • SearchApi
    • Settings
    • ShareableApi
    • Slack
    • SlugApi
    • SubscribableApi
    • Survey
    • Team
    • TenantApi
    • TestApi
    • ThemeApi
    • Timeline
    • TranslationApi
    • Update
    • Users
    • VisualisationApi
    • WorkflowApi
    • Wysiwyg

TestAPI module

This module contains dependencies, helpers and base classes for application tests.

Add tests to your modules!

Module tests should live in the module that provides the functionality that needs testing. Add tests to the Tests dir in your module, eg Modules/ExampleModule/Tests.

  • PHP tests should be within a Unit or Feature dir and ideally nested within a sub dir under that based on type. Eg. Modules/ExampleModule/Tests/Unit/Service/MyServiceTest.php. As long as your test file is in Modules/ExampleModule/Tests and ends with Test.php it should get detected.
  • Cypress tests MUST be in Modules/ExampleModule/Tests/Integration and end in spec.js for them to be detected. Cypress tests calling seeders that live in that module need to supply full namesapce with \ escaped. eg.
    cy.seed("Modules\\Example\\Database\\Seeders\\ExampleDatabaseSeeder")
    

Testing components supplied by a module.

Using the base theme to serve dynamic components so they can be tested.

  1. Create controller in your module, eg class CypressTestController extends CypressController
  2. Add a method like so:
    public function myComponent(): Response
    {
        return Inertia::render(CypressController::DYNAMIC_COMPONENT_PAGE, [
            'component' => 'my-module-vue-component',
            'componentProps' => [ 'foo' => 'bar' ],
        ]);
    }
    
  3. Add routes/tests.php to your module. NOTE: all tests route paths will start with /__test__ and route name will be prefixed with test.
  4. In the cypress integration, cy.visit({route: 'test.my.route.name'})

Base Test Class

All PHP tests should extend Modules\TestApi\Tests\TestCase

Request Mocking

This includes a dependency for Request Factories which are great for mocking requests.


Trait setUp methods

A test trait can provide a method that gets called in setUp automatically by using the naming convention camelTraitNameSetUp. Eg adding a trait MyTestTrait to your test and if it contains the method myTestTraitSetUp then that will get called in the test setup.

Edit this page
Prev
TenantApi
Next
ThemeApi