/**
  * Test resolve() when a UUID corresponds to an entity.
  */
 public function testResolveWithEntity()
 {
     $uuid = '392eab92-35c2-4625-872d-a9dab4da008e';
     $entity = $this->getMock('Drupal\\Core\\Entity\\EntityInterface');
     $entity->expects($this->once())->method('id')->will($this->returnValue(1));
     $this->entityManager->expects($this->once())->method('loadEntityByUuid')->with('test_type', $uuid)->will($this->returnValue($entity));
     $normalizer = $this->getMock('Drupal\\serialization\\EntityResolver\\UuidReferenceInterface');
     $normalizer->expects($this->once())->method('getUuid')->with(array())->will($this->returnValue($uuid));
     $this->assertSame(1, $this->resolver->resolve($normalizer, array(), 'test_type'));
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Mock the Config object, but methods will be mocked in the test class.
     $this->config = $this->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')->disableOriginalConstructor()->getMock();
     // Mock the ConfigFactory service.
     $this->configFactory = $this->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')->disableOriginalConstructor()->getMock();
     $this->configFactory->expects($this->any())->method('get')->with('key.default_config')->willReturn($this->config);
     // Mock ConfigEntityStorage object, but methods will be mocked in the test
     // class.
     $this->configStorage = $this->getMockBuilder('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock();
     // Mock EntityManager service.
     $this->entityManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->entityManager->expects($this->any())->method('getStorage')->with('key')->willReturn($this->configStorage);
     // Create a dummy container.
     $this->container = new ContainerBuilder();
     $this->container->set('entity.manager', $this->entityManager);
     $this->container->set('config.factory', $this->configFactory);
     // Each test class should call \Drupal::setContainer() in its own setUp
     // method so that test classes can add mocked services to the container
     // without affecting other test classes.
 }