diff --git a/core/modules/rest/tests/src/Unit/UserRegistrationResourceTest.php b/core/modules/rest/tests/src/Unit/UserRegistrationResourceTest.php index 844b845..2c1d2fc 100644 --- a/core/modules/rest/tests/src/Unit/UserRegistrationResourceTest.php +++ b/core/modules/rest/tests/src/Unit/UserRegistrationResourceTest.php @@ -64,12 +64,22 @@ public function getProtectedMethod($method) { } public function testValidate() { + + $violations = $this->getMockBuilder('Drupal\Core\Entity\EntityConstraintViolationList') + ->setMethods(['filterByFieldAccess']) + ->disableOriginalConstructor() + ->getMock(); + + $violations->expects($this->once()) + ->method('filterByFieldAccess') + ->will($this->returnValue(array())); + $entity = $this->getMockBuilder('Drupal\user\Entity\User') ->disableOriginalConstructor() ->getMock(); $entity->expects($this->once()) ->method('validate') - ->will($this->returnValue(array())); + ->will($this->returnValue($violations)); $method = $this->getProtectedMethod('validate'); // No exception is thrown. @@ -98,9 +108,19 @@ public function testFailedValidate() { $entity = $this->getMockBuilder('Drupal\user\Entity\User') ->disableOriginalConstructor() ->getMock(); + + $violations = $this->getMockBuilder('Drupal\Core\Entity\EntityConstraintViolationList') + ->setConstructorArgs([$entity, [$violation1, $violation2]]) + ->setMethods(['filterByFieldAccess']) + ->getMock(); + + $violations->expects($this->once()) + ->method('filterByFieldAccess') + ->will($this->returnValue([])); + $entity->expects($this->once()) ->method('validate') - ->will($this->returnValue(array($violation1, $violation2))); + ->will($this->returnValue($violations)); $method = $this->getProtectedMethod('validate'); // No exception is thrown. @@ -117,32 +137,17 @@ public function testEmptyPost() { /** * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage Invalid entity type. - */ - public function testInvalidEntityTypePost() { - $entity = $this->getMockBuilder('Drupal\user\Entity\User') - ->disableOriginalConstructor() - ->getMock(); - $entity->expects($this->once()) - ->method('getEntityTypeId') - ->will($this->returnValue('node')); - $this->testClass->post($entity); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException - * @expectedExceptionMessage Only new user accounts can be created. + * @expectedExceptionMessage Only new user accounts can be registered. */ public function testExistedEntityPost() { $entity = $this->getMockBuilder('Drupal\user\Entity\User') ->disableOriginalConstructor() ->getMock(); - $entity->expects($this->once()) - ->method('getEntityTypeId') - ->will($this->returnValue('user')); + $entity->expects($this->once()) ->method('isNew') ->will($this->returnValue(FALSE)); + $this->testClass->post($entity); } @@ -162,9 +167,6 @@ public function testRegistrationAdminOnlyPost() { ->disableOriginalConstructor() ->getMock(); $entity->expects($this->once()) - ->method('getEntityTypeId') - ->will($this->returnValue('user')); - $entity->expects($this->once()) ->method('isNew') ->will($this->returnValue(TRUE)); $this->testClass->post($entity); @@ -185,14 +187,25 @@ public function testInvalidRolesPost() { ->disableOriginalConstructor() ->getMock(); $entity->expects($this->once()) - ->method('getEntityTypeId') - ->will($this->returnValue('user')); - $entity->expects($this->once()) ->method('isNew') ->will($this->returnValue(TRUE)); $entity->expects($this->once()) ->method('getRoles') ->will($this->returnValue(array('administrator'))); + + $violations = $this->getMockBuilder('Drupal\Core\Entity\EntityConstraintViolationList') + ->setMethods(['filterByFieldAccess']) + ->disableOriginalConstructor() + ->getMock(); + + $violations->expects($this->any()) + ->method('filterByFieldAccess') + ->will($this->returnValue(array())); + + $entity->expects($this->once()) + ->method('validate') + ->will($this->returnValue($violations)); + $this->testClass->post($entity); }