/**
  * 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;
 }
Example #2
0
 /**
  * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException
  */
 public function testSaveWithException()
 {
     $taxClass = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', [], '', false);
     $this->groupFactory->expects($this->once())->method('create')->willReturn($this->groupModel);
     $this->group->expects($this->atLeastOnce())->method('getCode')->willReturn('Code');
     $this->group->expects($this->atLeastOnce())->method('getId')->willReturn(false);
     $this->group->expects($this->atLeastOnce())->method('getTaxClassId')->willReturn(234);
     $this->group->expects($this->atLeastOnce())->method('getTaxClassId')->willReturn(17);
     $this->groupModel->expects($this->once())->method('setCode')->with('Code');
     $this->groupModel->expects($this->once())->method('setTaxClassId')->with(234);
     $this->taxClassRepository->expects($this->once())->method('get')->with(234)->willReturn($taxClass);
     $taxClass->expects($this->once())->method('getClassType')->willReturn('CUSTOMER');
     $this->groupResourceModel->expects($this->once())->method('save')->with($this->groupModel)->willThrowException(new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Customer Group already exists.')));
     $this->model->save($this->group);
 }