class ViewUIObjectTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php \Drupal\Tests\views_ui\Unit\ViewUIObjectTest
@coversDefaultClass \Drupal\views_ui\ViewUI @group views_ui
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\views_ui\Unit\ViewUIObjectTest
Expanded class hierarchy of ViewUIObjectTest
File
- core/
modules/ views_ui/ tests/ src/ Unit/ ViewUIObjectTest.php, line 20 - Contains \Drupal\Tests\views_ui\Unit\ViewUIObjectTest.
Namespace
Drupal\Tests\views_ui\UnitView source
class ViewUIObjectTest extends UnitTestCase {
/**
* Tests entity method decoration.
*/
public function testEntityDecoration() {
$method_args = array();
$method_args['setOriginalId'] = array(
12,
);
$method_args['setStatus'] = array(
TRUE,
);
$method_args['enforceIsNew'] = array(
FALSE,
);
$method_args['label'] = array(
LanguageInterface::LANGCODE_NOT_SPECIFIED,
);
$reflection = new \ReflectionClass('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
$interface_methods = array();
foreach ($reflection
->getMethods() as $reflection_method) {
$interface_methods[] = $reflection_method
->getName();
// EntityInterface::isNew() is missing from the list of methods, because it
// calls id(), which breaks the ->expect($this->once()) call. Call it later.
// EntityInterface::isSyncing() is only called during syncing process.
// EntityInterface::isUninstalling() is only called during uninstallation
// process. EntityInterface::getConfigDependencyName() and
// ConfigEntityInterface::calculateDependencies() are only used for
// dependency management.
if (!in_array($reflection_method
->getName(), [
'isNew',
'isSyncing',
'isUninstalling',
'getConfigDependencyKey',
'getConfigDependencyName',
'calculateDependencies',
])) {
if (count($reflection_method
->getParameters()) == 0) {
$method_args[$reflection_method
->getName()] = array();
}
}
}
$storage = $this
->getMock('Drupal\\views\\Entity\\View', $interface_methods, array(
array(),
'view',
));
$executable = $this
->getMockBuilder('Drupal\\views\\ViewExecutable')
->disableOriginalConstructor()
->setConstructorArgs(array(
$storage,
))
->getMock();
$storage
->set('executable', $executable);
$view_ui = new ViewUI($storage);
foreach ($method_args as $method => $args) {
$method_mock = $storage
->expects($this
->once())
->method($method);
foreach ($args as $arg) {
$method_mock
->with($this
->equalTo($arg));
}
call_user_func_array(array(
$view_ui,
$method,
), $args);
}
$storage
->expects($this
->once())
->method('isNew');
$view_ui
->isNew();
}
/**
* Tests the isLocked method.
*/
public function testIsLocked() {
$storage = $this
->getMock('Drupal\\views\\Entity\\View', array(), array(
array(),
'view',
));
$executable = $this
->getMockBuilder('Drupal\\views\\ViewExecutable')
->disableOriginalConstructor()
->setConstructorArgs(array(
$storage,
))
->getMock();
$storage
->set('executable', $executable);
$account = $this
->getMock('Drupal\\Core\\Session\\AccountInterface');
$account
->expects($this
->exactly(2))
->method('id')
->will($this
->returnValue(1));
$container = new ContainerBuilder();
$container
->set('current_user', $account);
\Drupal::setContainer($container);
$view_ui = new ViewUI($storage);
// A view_ui without a lock object is not locked.
$this
->assertFalse($view_ui
->isLocked());
// Set the lock object with a different owner than the mocked account above.
$lock = (object) array(
'owner' => 2,
'data' => array(),
'updated' => (int) $_SERVER['REQUEST_TIME'],
);
$view_ui->lock = $lock;
$this
->assertTrue($view_ui
->isLocked());
// Set a different lock object with the same object as the mocked account.
$lock = (object) array(
'owner' => 1,
'data' => array(),
'updated' => (int) $_SERVER['REQUEST_TIME'],
);
$view_ui->lock = $lock;
$this
->assertFalse($view_ui
->isLocked());
}
/**
* Tests serialization of the ViewUI object.
*/
public function testSerialization() {
// Set a container so the DependencySerializationTrait has it.
$container = new ContainerBuilder();
\Drupal::setContainer($container);
$storage = new View([], 'view');
$executable = $this
->getMockBuilder('Drupal\\views\\ViewExecutable')
->disableOriginalConstructor()
->setConstructorArgs([
$storage,
])
->getMock();
$storage
->set('executable', $executable);
$view_ui = new ViewUI($storage);
// Make sure the executable is returned before serializing.
$this
->assertInstanceOf('Drupal\\views\\ViewExecutable', $view_ui
->getExecutable());
$serialized = serialize($view_ui);
// Make sure the ViewExecutable class is not found in the serialized string.
$this
->assertSame(strpos($serialized, '"Drupal\\views\\ViewExecutable"'), FALSE);
$unserialized = unserialize($serialized);
$this
->assertInstanceOf('Drupal\\views_ui\\ViewUI', $unserialized);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 259 | |
ViewUIObjectTest:: |
public | function | Tests entity method decoration. | |
ViewUIObjectTest:: |
public | function | Tests the isLocked method. | |
ViewUIObjectTest:: |
public | function | Tests serialization of the ViewUI object. |