public function BlazyTest::testTypecast in Blazy 7
Tests typecasting.
@covers \Drupal\blazy_ui\Form\BlazySettingsForm::submitForm @covers \Drupal\blazy\BlazyManager::config @covers \Drupal\blazy\BlazyManager::typecast
File
- tests/
Blazy.test, line 94
Class
- BlazyTest
- Tests the Blazy configuration options and permission controls.
Code
public function testTypecast() {
// Login as the admin user.
$this
->drupalLogin($this->adminUser);
$settings_path = 'admin/config/media/blazy';
// Load the form.
$this
->drupalGet($settings_path);
$this
->assertResponse(200, 'Administrative user can reach the "Blazy UI" form.');
// Test submitting the form.
// Enable Picture support which was disabled by default.
$edit['responsive_image'] = TRUE;
$this
->drupalPost($settings_path, $edit, t('Save configuration'));
// We must have a Drupal standard message on saving a form.
$this
->assertText(t('The configuration options have been saved.'), 'Blazy config has been updated.');
// Verifies that default values are set, and correctly typecast.
$config = blazy()
->config();
$this
->assertEqual(blazy()
->config('admin_css', TRUE), TRUE, t('Admin CSS is enabled.'));
$this
->assertEqual(blazy()
->config('responsive_image', FALSE), TRUE, t('Picture support was disabled, now enabled.'));
$this
->assertEqual(blazy()
->config('pages'), BlazyDefault::PAGES, t('Pages for BlazyFilter match default.'));
// Verifies our dot notation array works.
$this
->assertEqual(blazy()
->config('blazy.saveViewportOffsetDelay'), 50, t('blazy.saveViewportOffsetDelay dot notation value matches 50.'));
// Must have blazy on the saved settings.
$this
->assertTrue(array_key_exists('blazy', $config), t('Blazy JS option array is correctly saved.'));
// Also verifies that the cast values match the variable_get() on saving.
$this
->assertEqual(variable_get('blazy.settings', []), $config, t('Typecast values match variable_get() values.'));
}