/**
  * Tests that an instance removed from the registry will cause the registry to load the model again.
  *
  * @return void
  */
 public function testRemove()
 {
     $groupId = 1;
     $group = $this->getMockBuilder('Magento\\Customer\\Model\\Group')->disableOriginalConstructor()->setMethods(['load', 'getId', '__wakeup'])->getMock();
     $group->expects($this->exactly(2))->method('load')->with($groupId)->will($this->returnValue($group));
     $group->expects($this->exactly(4))->method('getId')->will($this->returnValue($groupId));
     $this->groupFactory->expects($this->exactly(2))->method('create')->will($this->returnValue($group));
     $actual = $this->unit->retrieve($groupId);
     $this->assertSame($group, $actual);
     $this->unit->remove($groupId);
     $actual = $this->unit->retrieve($groupId);
     $this->assertSame($group, $actual);
 }
 /**
  * @magentoDataFixture Magento/Customer/_files/customer_group.php
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testRemove()
 {
     $groupId = $this->_findGroupIdWithCode(self::GROUP_CODE);
     $group = $this->_model->retrieve($groupId);
     $this->assertInstanceOf('\\Magento\\Customer\\Model\\Group', $group);
     $group->delete();
     $this->_model->remove($groupId);
     $this->_model->retrieve($groupId);
 }
 public function testDelete()
 {
     $groupId = 6;
     $this->group->expects($this->once())->method('getId')->willReturn($groupId);
     $this->groupRegistry->expects($this->once())->method('retrieve')->with($groupId)->willReturn($this->groupModel);
     $this->groupModel->expects($this->once())->method('usesAsDefault')->willReturn(false);
     $this->groupModel->expects($this->once())->method('delete');
     $this->groupRegistry->expects($this->once())->method('remove')->with($groupId);
     $this->assertTrue($this->model->delete($this->group));
 }
Esempio n. 4
0
 /**
  * Delete customer group by ID.
  *
  * @param int $id
  * @return bool true on success
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  * @throws \Magento\Framework\Exception\StateException If customer group cannot be deleted
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function deleteById($id)
 {
     $groupModel = $this->groupRegistry->retrieve($id);
     if ($id <= 0 || $groupModel->usesAsDefault()) {
         throw new \Magento\Framework\Exception\StateException(__('Cannot delete group.'));
     }
     $groupModel->delete();
     $this->groupRegistry->remove($id);
     return true;
 }
 /**
  * Create a test group.
  *
  * @param CustomerGroup $group The group to create and save.
  * @return int The group Id of the group that was created.
  */
 private function createGroup($group)
 {
     $groupId = $this->groupRepository->save($group)->getId();
     $this->assertNotNull($groupId);
     $newGroup = $this->groupRepository->getById($groupId);
     $this->assertEquals($groupId, $newGroup->getId(), 'The group id does not match.');
     $this->assertEquals($group->getCode(), $newGroup->getCode(), 'The group code does not match.');
     $this->assertEquals($group->getTaxClassId(), $newGroup->getTaxClassId(), 'The group tax class id does not match.');
     $this->groupRegistry->remove($groupId);
     return $groupId;
 }
 /**
  * {@inheritdoc}
  */
 public function deleteGroup($groupId)
 {
     if (!$this->canDelete($groupId)) {
         throw new StateException('Cannot delete group.');
     }
     // Get group so we can throw an exception if it doesn't exist
     $this->getGroup($groupId);
     $customerGroup = $this->_groupFactory->create();
     $customerGroup->setId($groupId);
     $customerGroup->delete();
     $this->_groupRegistry->remove($groupId);
     return true;
 }