public function testIsValidTrue() { $checkoutSession = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->getMock(); $checkoutSession->expects($this->at(0))->method('__call')->with('getLastSuccessQuoteId')->will($this->returnValue(1)); $checkoutSession->expects($this->at(1))->method('__call')->with('getLastQuoteId')->will($this->returnValue(1)); $checkoutSession->expects($this->at(2))->method('__call')->with('getLastOrderId')->will($this->returnValue(1)); $this->assertTrue($this->object->isValid($checkoutSession)); }
public function testValidator() { $this->testInstance->expects($this->any())->method('getValidationObject')->will($this->returnValue($this->testValidator)); $this->testValidator->expects($this->any())->method('getValidator')->will($this->returnValue($value = uniqid())); $this->testValidator->expects($this->any())->method('passes')->will($this->returnValue($valuePasses = uniqid())); $this->assertSame($this->testValidator, $this->testInstance->extractValidator()); $this->assertSame($value, $this->testInstance->getValidator()); $this->assertSame($valuePasses, $this->testInstance->isValid()); }
/** * @covers DmCommon\Form\BaseForm */ public function testGetValidationClassAddsSuccessClassToGivenClassIfThereAreNoMessages() { $givenClass = 'foo'; $elementMock = $this->getMock('Zend\\Form\\Element', ['getMessages']); $elementMock->expects($this->once())->method('getMessages')->will($this->returnValue([])); if (!$this->sut->isValid()) { $this->fail(print_r($this->sut->getMessages(), true)); } $actualResult = $this->sut->getValidationClass($elementMock, $givenClass); $this->assertEquals($givenClass . ' has-success', $actualResult); }
public function testIsValidReturnAddMessagesCall() { $value = [AdvancedPricing::COL_TIER_PRICE_WEBSITE => 'tier value']; $allWebsitesValue = 'not tier|group price website value'; $colTierPriceWebsite = false; $expectedMessages = [AdvancedPricing\Validator\Website::ERROR_INVALID_WEBSITE]; $this->website->expects($this->once())->method('_clearMessages'); $this->website->expects($this->any())->method('getAllWebsitesValue')->willReturn($allWebsitesValue); $this->storeResolver->method('getWebsiteCodeToId')->willReturnMap([[$value[AdvancedPricing::COL_TIER_PRICE_WEBSITE], $colTierPriceWebsite]]); $this->website->expects($this->any())->method('_addMessages')->with($expectedMessages); $this->website->isValid($value); }
/** * @dataProvider isValidAddMessagesCallDataProvider * * @param array $value * @param bool $hasEmptyColumns * @param array $customerGroups * @param array $expectedMessages */ public function testIsValidAddMessagesCall($value, $hasEmptyColumns, $customerGroups, $expectedMessages) { $this->groupPrice->expects($this->once())->method('isValidValueAndLength')->willReturn(true); $this->groupPrice->expects($this->any())->method('hasEmptyColumns')->willReturn($hasEmptyColumns); $this->setPropertyValue($this->groupPrice, 'customerGroups', $customerGroups); $this->groupPrice->expects($this->once())->method('_addMessages')->with($expectedMessages); $this->groupPrice->isValid($value); }
/** * @dataProvider isValidAddMessagesCallDataProvider * * @param array $value * @param bool $hasEmptyColumns * @param array $customerGroups * @param array $expectedMessages */ public function testIsValidAddMessagesCall($value, $hasEmptyColumns, $customerGroups, $expectedMessages) { $priceContextMock = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], ['\\Magento\\Framework\\Json\\Helper\\Data', '\\Magento\\ImportExport\\Helper\\Data', '\\Magento\\ImportExport\\Model\\ResourceModel\\Import\\Data', '\\Magento\\Eav\\Model\\Config', '\\Magento\\Framework\\App\\ResourceConnection', '\\Magento\\ImportExport\\Model\\ResourceModel\\Helper', '\\Magento\\Framework\\Stdlib\\StringUtils', 'ProcessingErrorAggregatorInterface'], '', false); $this->tierPrice->expects($this->once())->method('isValidValueAndLength')->willReturn(true); $this->tierPrice->expects($this->any())->method('hasEmptyColumns')->willReturn($hasEmptyColumns); $this->setPropertyValue($this->tierPrice, 'customerGroups', $customerGroups); $searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $this->searchCriteriaBuilder->expects($this->any())->method('create')->willReturn($searchCriteria); $groupSearchResult = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], '', false); $this->groupRepository->expects($this->any())->method('getList')->with($searchCriteria)->willReturn($groupSearchResult); $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass(); $groupTest->expects($this->once())->method('getCode'); $groupTest->expects($this->any())->method('getId'); $groups = [$groupTest]; $groupSearchResult->expects($this->any())->method('getItems')->willReturn($groups); $this->tierPrice->init($priceContextMock); $this->tierPrice->isValid($value); }