/** * Setup for the tests of the ::load() method. */ function setupTestLoad() { // Use an entity type object which has the methods enabled which are being // called by the protected method Entity::getEntityTypeFromStaticClass(). $methods = get_class_methods('Drupal\\Core\\Entity\\EntityType'); unset($methods[array_search('getClass', $methods)]); unset($methods[array_search('setClass', $methods)]); $this->entityType = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityType')->disableOriginalConstructor()->setMethods($methods)->getMock(); // Base our mocked entity on a real entity class so we can test if calling // Entity::load() on the base class will bubble up to an actual entity. $this->entityTypeId = 'entity_test_mul'; $methods = get_class_methods('Drupal\\entity_test\\Entity\\EntityTestMul'); unset($methods[array_search('load', $methods)]); unset($methods[array_search('loadMultiple', $methods)]); unset($methods[array_search('create', $methods)]); $this->entity = $this->getMockBuilder('Drupal\\entity_test\\Entity\\EntityTestMul')->disableOriginalConstructor()->setMethods($methods)->getMock(); $this->entityType->setClass(get_class($this->entity)); $this->entityManager->expects($this->once())->method('getDefinitions')->will($this->returnValue(array($this->entityTypeId => $this->entityType))); $this->entityType->expects($this->any())->method('id')->will($this->returnValue($this->entityTypeId)); }