fpp.helper.test in Fieldable Panels Panes (FPP) 7
A base class for the Fieldable Panels Panes tests, provides shared methods.
File
tests/fpp.helper.testView source
<?php
/**
* @file
* A base class for the Fieldable Panels Panes tests, provides shared methods.
*/
/**
* A base class for the Fieldable Panels Panes tests, provides shared methods.
*/
abstract class FppTestHelper extends DrupalWebTestCase {
/**
* Admin user.
*
* @var \StdClass
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'fieldable_panels_panes';
parent::setUp($modules);
// Some default values to work with.
$this->bundle = 'fieldable_panels_pane';
$this->title = t('Test');
}
/**
* Create an admin-level user.
*
* @param array $perms
* Any permissions to be added to the user.
*
* @return object
* A standard Drupal user object.
*/
public function createAdminUser(array $perms = array()) {
// Create a user with the admin permission.
$permissions = array(
// The master permission for FPP.
'administer fieldable panels panes',
// Required for Drupal core 7.50+, otherwise the user won't have access to
// the field settings.
'administer fields',
);
return $this
->createUser(array_merge($permissions, $perms));
}
/**
* Create a new user account with limited permissions.
*
* @param array $perms
* Any permissions to be added to the user.
*
* @return object
* A standard Drupal user object.
*/
public function createUser(array $perms = array()) {
// Reset the static variable used to identify permissions, otherwise it's
// possible the permissions check in drupalCreateUser will fail.
$this
->checkPermissions(array(), TRUE);
cache_clear_all();
return $this
->drupalCreateUser($perms);
}
/**
* Create an image of a specific size & type.
*
* @param string $image_size
* The size of the requested image in 'XxY' format; defaults to '200x200'.
* @param string $format
* The image format to use; defaults to 'png'.
* @param string $scheme
* The storage scheme to use; defaults to 'public'.
*
* @return string
* The URL to a public file.
*/
public function generateImage($image_size = '200x200', $format = 'png', $scheme = 'public') {
// Only proceed if the Devel Generate module is installed.
if (module_exists('devel_generate')) {
// Load the Devel Generate image generator logic.
module_load_include('inc', 'devel_generate', 'image.devel_generate');
$image_format = 'png';
$image_size = '200x200';
$temp_image = devel_generate_image($image_format, $image_size, $image_size);
return file_unmanaged_move($temp_image, $scheme . '://');
}
else {
$this
->error('The Devel Generate module is not enabled, it must be added to the $modules array in the setUp() method for this test class.');
}
}
/**
* Create an image file object of a specific size & type.
*
* @param string $image_size
* The size of the requested image in 'XxY' format; defaults to '200x200'.
* @param string $format
* The image format to use, defaults to 'png'.
* @param string $scheme
* The file storage scheme, should be either 'private' or 'public'; defaults
* to 'public'.
*
* @return object
* The file object for the generated image.
*/
public function generateImageFile($image_size = '200x200', $format = 'png', $scheme = 'public') {
// Generate a test image.
$image_uri = $this
->generateImage($image_size, $format, $scheme);
// Create a file object for this image.
$file = new StdClass();
$file->fid = NULL;
$file->uid = 1;
$file->uri = $image_uri;
$file->filemime = file_get_mimetype($image_uri);
$file->filesize = filesize($image_uri);
$file->status = 1;
$file->timestamp = filemtime($image_uri);
$saved_file = file_save($file);
return $saved_file;
}
}
Classes
Name | Description |
---|---|
FppTestHelper | A base class for the Fieldable Panels Panes tests, provides shared methods. |