public function testValidate() { $this->_model->addData(["include_in_menu" => false, "is_active" => false, 'name' => 'test']); $this->assertNotEmpty($this->_model->validate()); }
/** * Validate category process * * @param Category $category * @return void * @throws \Magento\Framework\Exception\LocalizedException */ protected function validateCategory(Category $category) { $useConfigFields = []; foreach ($this->useConfigFields as $field) { if (!$category->getData($field)) { $useConfigFields[] = $field; } } $category->setData('use_post_data_config', $useConfigFields); $validate = $category->validate(); if ($validate !== true) { foreach ($validate as $code => $error) { if ($error === true) { $attribute = $this->categoryResource->getAttribute($code)->getFrontend()->getLabel(); throw new \Magento\Framework\Exception\LocalizedException(__('Attribute "%1" is required.', $attribute)); } else { throw new \Magento\Framework\Exception\LocalizedException(__($error)); } } } $category->unsetData('use_post_data_config'); }
/** * {@inheritdoc} */ public function validate() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'validate'); if (!$pluginInfo) { return parent::validate(); } else { return $this->___callPlugins('validate', func_get_args(), $pluginInfo); } }