/** * {@inheritdoc} */ public function removeMember(ZoneMemberInterface $zoneMember) { $zoneMembers = $this->getElement('zone_members'); $items = $zoneMembers->findAll('css', 'div[data-form-collection="item"]'); /** @var NodeElement $item */ foreach ($items as $item) { $selectedItem = $item->find('css', 'option[selected="selected"]'); if (null === $selectedItem) { throw new ElementNotFoundException($this->getDriver(), 'selected option', 'css', 'option[selected="selected"]'); } if ($selectedItem->getValue() === $zoneMember->getCode()) { $this->getDeleteButtonForCollectionItem($item)->click(); break; } } }
function it_matches_all_zones_by_scope_when_one_zone_for_address_is_defined(RepositoryInterface $repository, AddressInterface $address, ZoneMemberInterface $memberCountry, ZoneInterface $zoneCountry) { $repository->findBy(['scope' => 'shipping'])->willReturn([$zoneCountry]); $address->getCountryCode()->willReturn('US'); $memberCountry->getCode()->willReturn('US'); $zoneCountry->getType()->willReturn(ZoneInterface::TYPE_COUNTRY); $zoneCountry->getMembers()->willReturn([$memberCountry]); $memberCountry->getBelongsTo()->willReturn($zoneCountry); $this->matchAll($address, 'shipping')->shouldReturn([$zoneCountry]); }
/** * @param AddressInterface $address * @param ZoneMemberInterface $member * * @return bool * * @throws \InvalidArgumentException */ protected function addressBelongsToZoneMember(AddressInterface $address, ZoneMemberInterface $member) { switch ($type = $member->getBelongsTo()->getType()) { case ZoneInterface::TYPE_PROVINCE: return null !== $address->getProvinceCode() && $address->getProvinceCode() === $member->getCode(); case ZoneInterface::TYPE_COUNTRY: return null !== $address->getCountryCode() && $address->getCountryCode() === $member->getCode(); case ZoneInterface::TYPE_ZONE: $zone = $this->getZoneByCode($member->getCode()); return $this->addressBelongsToZone($address, $zone); default: throw new \InvalidArgumentException(sprintf('Unexpected zone type "%s".', $type)); } }