Tag: sandbox-mode



A recent bug with Ultimate Member roles reminded me how difficult it is to create Twitch subscriber based features without a channel that offers a subscription program to perform testing. The alternative is sandbox-mode which makes use of sample data from Twitch.tv and other sources, to behave as if API calls have been made.

Development Only

This feature is intended for developers during development of beta versions. A sandbox is an environment designed for practice, testing new code, and not for testing a live site. Never activate this mode on a live-site.


TwitchPress Sandbox Mode Active

Sandbox Generator

The Sandbox-mode Generator option allows the mode to generate random data, rather than simply using hardcoded values. This requires a developer to create a procedure that will generate seemingly valid values. This is done based on validation parameters that would normally be applied to each value of data. So in many cases, we wouldn’t be able to tell the difference. TwitchPress Sandbox Mode Generator

A generator procedure won’t always (or even often) simply create random values though. My initial need was to generate WP users, based on real Twitch channels and randomly generate subscription data for those users. So I require both real data (to ensure some real validation and real API calls work correctly) and randomly generated data for the purpose of testing new procedures i.e. a procedure that would otherwise need real visitors to register and use features. I can’t get enough people to do that, at the time I need them to and at a rate that is helpful to me while I watch the log. I created something that would be the next best thing.

Generator Off Option

When the Sandbox-Mode Generator box isn’t checked, TwitchPress will only use hardcoded data which involves manual entry and can be time-consuming. This is ideal for very precise tests, which are normally small anyway.

The generator is off by default and not every feature in the plugin will be supported due to the work involved.

False/Failed Returns Option

This option allows a little more natural behavior to be applied. A lot of functions won’t always return a full set of records or a response that we can do much with. A real response might include an error and contain very little data compared to a successful response.

TwitchPress Sandbox Mode False ReturnsIn some cases, it is entirely normal to get a short response i.e. when we query if someone is a subscriber to our own Twitch channel, but they aren’t. The Twitch API will respond with a very basic and small set of values when compared to a positive response which would tell us far more.

We need false/failed responses from the API to ensure the plugin handles them properly. So when in sandbox mode we need the same behavior. This means I have to make TwitchPress randomly switch between the data and the tester/developer will see a natural randomness during testing just as if they were processing many Twitch channels/users for real.

Help Maintain Test Data

The more test data the quicker we can fix any bugs that come up. This will be a simple task of copying and pasting samples from API documentation. If you know GitHub then this is a task you can get involved with. Just 30 minutes of your time, adding more sample data or just suggesting samples in the form of GitHub issues.

Here is an image of the sample data offered by Twitch.tv within developer documentation for their API.

Twitch Example API Response if user is subscribed to the channel