/** * @covers ::validate */ public function testValidateNoMatchingFormats() { $this->filterUninstallValidator->expects($this->once())->method('getFilterDefinitionsByProvider')->willReturn(['test_filter_plugin1' => ['id' => 'test_filter_plugin1', 'provider' => 'filter_test'], 'test_filter_plugin2' => ['id' => 'test_filter_plugin2', 'provider' => 'filter_test'], 'test_filter_plugin3' => ['id' => 'test_filter_plugin3', 'provider' => 'filter_test'], 'test_filter_plugin4' => ['id' => 'test_filter_plugin4', 'provider' => 'filter_test']]); $filter_plugin_enabled = $this->getMockForAbstractClass('Drupal\\filter\\Plugin\\FilterBase', [['status' => TRUE], '', ['provider' => 'filter_test']]); $filter_plugin_disabled = $this->getMockForAbstractClass('Drupal\\filter\\Plugin\\FilterBase', [['status' => FALSE], '', ['provider' => 'filter_test']]); // The first format has 2 matching and enabled filters, but the loop breaks // after finding the first one. $filter_plugin_collection1 = $this->getMockBuilder('Drupal\\filter\\FilterPluginCollection')->disableOriginalConstructor()->getMock(); $filter_plugin_collection1->expects($this->exactly(3))->method('has')->willReturnMap([['test_filter_plugin1', FALSE], ['test_filter_plugin2', TRUE], ['test_filter_plugin3', TRUE], ['test_filter_plugin4', TRUE]]); $filter_plugin_collection1->expects($this->exactly(2))->method('get')->willReturnMap([['test_filter_plugin2', $filter_plugin_disabled], ['test_filter_plugin3', $filter_plugin_enabled], ['test_filter_plugin4', $filter_plugin_enabled]]); $filter_format1 = $this->getMock('Drupal\\filter\\FilterFormatInterface'); $filter_format1->expects($this->once())->method('filters')->willReturn($filter_plugin_collection1); $filter_format1->expects($this->once())->method('label')->willReturn('Filter Format 1 Label'); // The second filter format only has one matching and enabled filter. $filter_plugin_collection2 = $this->getMockBuilder('Drupal\\filter\\FilterPluginCollection')->disableOriginalConstructor()->getMock(); $filter_plugin_collection2->expects($this->exactly(4))->method('has')->willReturnMap([['test_filter_plugin1', FALSE], ['test_filter_plugin2', FALSE], ['test_filter_plugin3', FALSE], ['test_filter_plugin4', TRUE]]); $filter_plugin_collection2->expects($this->exactly(1))->method('get')->with('test_filter_plugin4')->willReturn($filter_plugin_enabled); $filter_format2 = $this->getMock('Drupal\\filter\\FilterFormatInterface'); $filter_format2->expects($this->once())->method('filters')->willReturn($filter_plugin_collection2); $filter_format2->expects($this->once())->method('label')->willReturn('Filter Format 2 Label'); $this->filterUninstallValidator->expects($this->once())->method('getEnabledFilterFormats')->willReturn(['test_filter_format1' => $filter_format1, 'test_filter_format2' => $filter_format2]); $expected = ['Provides a filter plugin that is in use in the following filter formats: <em class="placeholder">Filter Format 1 Label, Filter Format 2 Label</em>']; $reasons = $this->filterUninstallValidator->validate($this->randomMachineName()); $this->assertSame($expected, $reasons); }
/** * @covers ::validate */ public function testValidateRequired() { $module = $this->randomMachineName(); $this->uninstallValidator->expects($this->once())->method('getModuleInfoByModule')->willReturn(['required' => TRUE, 'name' => $module]); $expected = ["The {$module} module is required"]; $reasons = $this->uninstallValidator->validate($module); $this->assertSame($expected, $this->castSafeStrings($reasons)); }
/** * @covers \opus\base\behaviors\TimestampBehavior::inject */ public function testUpdate() { $now = new Expression('NOW()'); $this->mock->expects($this->once())->method('getIsNewRecord')->will($this->returnValue(false)); $this->mock->expects($this->any())->method('hasAttribute')->will($this->returnValue(true)); $this->mock->expects($this->once())->method('setAttribute')->with('up', $now); $this->mock->validate(); }
/** * @covers ::validate */ public function testValidateRequired() { $module = $this->randomMachineName(); $this->uninstallValidator->expects($this->once())->method('getModuleInfoByModule')->willReturn(['required' => TRUE, 'name' => $module]); $expected = [SafeMarkup::format('The @module module is required', ['@module' => $module])]; $reasons = $this->uninstallValidator->validate($module); $this->assertSame($expected, $reasons); }
/** * @dataProvider validateDataProvider * @param bool[] $options * @param string[] $errors */ public function testValidate(array $options, array $errors) { $inputMock = $this->getMockForAbstractClass('Symfony\\Component\\Console\\Input\\InputInterface', [], '', false); $index = 0; foreach ($options as $option) { $inputMock->expects($this->at($index++))->method('getOption')->willReturn($option); } $this->assertEquals($errors, $this->command->validate($inputMock)); }
/** * @covers ::validate */ public function testValidateOutlineStorage() { $this->bookUninstallValidator->expects($this->once())->method('hasBookOutlines')->willReturn(TRUE); $this->bookUninstallValidator->expects($this->never())->method('hasBookNodes'); $module = 'book'; $expected = ['To uninstall Book, delete all content that is part of a book']; $reasons = $this->bookUninstallValidator->validate($module); $this->assertSame($expected, $this->castSafeStrings($reasons)); }
/** * @covers ::validate */ public function testValidateNoDeleted() { $field_storage = $this->getMockBuilder('Drupal\\field\\Entity\\FieldStorageConfig')->disableOriginalConstructor()->getMock(); $field_storage->expects($this->once())->method('isDeleted')->willReturn(FALSE); $this->fieldUninstallValidator->expects($this->once())->method('getFieldStoragesByModule')->willReturn([$field_storage]); $module = $this->randomMachineName(); $expected = ['Fields type(s) in use']; $reasons = $this->fieldUninstallValidator->validate($module); $this->assertSame($expected, $reasons); }
public function testValidate() { $option = $this->getMock('Magento\\Framework\\Setup\\Option\\TextConfigOption', [], [], '', false); $option->expects($this->exactly(3))->method('getName')->willReturn('Fake'); $optionsSet = [$option, $option, $option]; $configOption = $this->configOptionsList; $configOption->expects($this->once())->method('getOptions')->will($this->returnValue($optionsSet)); $configOption->expects($this->once())->method('validate')->will($this->returnValue([])); $this->collector->expects($this->exactly(2))->method('collectOptionsLists')->will($this->returnValue([$configOption])); $this->configModel->validate(['Fake' => null]); }
/** * @param $existingValue * @param $operator * @param $valueForValidate * @param $expectedResult * * @dataProvider validateAttributeDataProvider */ public function testValidate($existingValue, $operator, $valueForValidate, $expectedResult) { $objectMock = $this->getMock('Magento\\Framework\\Model\\AbstractModel', ['hasData', 'load', 'getId', 'getData'], [], '', false); $objectMock->expects($this->once())->method('hasData')->willReturn(false); $objectMock->expects($this->once())->method('getId')->willReturn(7); $objectMock->expects($this->once())->method('load')->with(7); $objectMock->expects($this->once())->method('getData')->willReturn($valueForValidate); $this->_condition->setOperator($operator); $this->_condition->setData('value_parsed', $existingValue); $this->assertEquals($expectedResult, $this->_condition->validate($objectMock), "Failed asserting that " . var_export($existingValue, true) . $operator . var_export($valueForValidate, true)); }
public function testValidateSetEntityAttributeValuesWithoutResource() { $product = $this->getMock('Magento\\Framework\\Model\\AbstractModel', ['someMethod', 'getResource', 'load'], [], '', false); $this->_condition->setAttribute('someAttribute'); $product->setAtribute('attribute'); $product->setId(12); $this->_configProperty->setValue($this->_condition, $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false)); $this->_entityAttributeValuesProperty->setValue($this->_condition, $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false)); $attribute = new \Magento\Framework\DataObject(); $attribute->setBackendType('multiselect'); $newResource = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product', ['getAttribute'], [], '', false); $newResource->expects($this->any())->method('getAttribute')->with('someAttribute')->will($this->returnValue($attribute)); $newResource->_config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false); $product->expects($this->atLeastOnce())->method('getResource')->willReturn($newResource); $this->_entityAttributeValuesProperty->setValue($this->_condition, [1 => [''], 2 => ['option1,option2,option3'], 3 => ['option1,option2,option3']]); $this->assertFalse($this->_condition->validate($product)); $attribute = new \Magento\Framework\DataObject(); $attribute->setBackendType(null); $attribute->setFrontendInput('multiselect'); $newResource = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product', ['getAttribute'], [], '', false); $newResource->expects($this->any())->method('getAttribute')->with('someAttribute')->will($this->returnValue($attribute)); $newResource->_config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false); $product->setResource($newResource); $product->setId(1); $product->setData('someAttribute', 'value'); $this->assertFalse($this->_condition->validate($product)); }
/** * Tests required validation. * * @covers ::validate * @covers ::isValidationRequired * @covers ::setValidationRequired * @covers ::save * @covers ::preSave * * @expectedException \LogicException * @expectedExceptionMessage Entity validation was skipped. */ public function testRequiredValidation() { $validator = $this->getMock('\\Symfony\\Component\\Validator\\ValidatorInterface'); /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */ $empty_violation_list = $this->getMockBuilder('\\Symfony\\Component\\Validator\\ConstraintViolationList')->setMethods(NULL)->getMock(); $validator->expects($this->at(0))->method('validate')->with($this->entity->getTypedData())->will($this->returnValue($empty_violation_list)); $this->typedDataManager->expects($this->any())->method('getValidator')->will($this->returnValue($validator)); /** @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit_Framework_MockObject_MockObject $storage */ $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface'); $storage->expects($this->any())->method('save')->willReturnCallback(function (ContentEntityInterface $entity) use($storage) { $entity->preSave($storage); }); $this->entityManager->expects($this->any())->method('getStorage')->with($this->entityTypeId)->will($this->returnValue($storage)); // Check that entities can be saved normally when validation is not // required. $this->assertFalse($this->entity->isValidationRequired()); $this->entity->save(); // Make validation required and check that if the entity is validated, it // can be saved normally. $this->entity->setValidationRequired(TRUE); $this->assertTrue($this->entity->isValidationRequired()); $this->entity->validate(); $this->entity->save(); // Check that the "validated" status is reset after saving the entity and // that trying to save a non-validated entity when validation is required // results in an exception. $this->assertTrue($this->entity->isValidationRequired()); $this->entity->save(); }
/** * @covers ::validate */ public function testValidateNoDeleted() { $field_storage = $this->getMockBuilder('Drupal\\field\\Entity\\FieldStorageConfig')->disableOriginalConstructor()->getMock(); $field_storage->expects($this->once())->method('isDeleted')->willReturn(FALSE); $field_type = $this->randomMachineName(); $field_storage->expects($this->once())->method('getType')->willReturn($field_type); $field_name = $this->randomMachineName(); $field_storage->expects($this->once())->method('getLabel')->willReturn($field_name); $this->fieldUninstallValidator->expects($this->once())->method('getFieldStoragesByModule')->willReturn([$field_storage]); $field_type_label = $this->randomMachineName(); $this->fieldUninstallValidator->expects($this->once())->method('getFieldTypeLabel')->willReturn($field_type_label); $module = $this->randomMachineName(); $expected = ["The <em class=\"placeholder\">{$field_type_label}</em> field type is used in the following field: {$field_name}"]; $reasons = $this->fieldUninstallValidator->validate($module); $this->assertSame($expected, $this->castSafeStrings($reasons)); }
/** * @covers ::validate */ public function testValidate() { $validator = $this->getMock('\\Symfony\\Component\\Validator\\ValidatorInterface'); /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */ $empty_violation_list = $this->getMockBuilder('\\Symfony\\Component\\Validator\\ConstraintViolationList')->setMethods(NULL)->getMock(); $non_empty_violation_list = clone $empty_violation_list; $violation = $this->getMock('\\Symfony\\Component\\Validator\\ConstraintViolationInterface'); $non_empty_violation_list->add($violation); $validator->expects($this->at(0))->method('validate')->with($this->entity->getTypedData())->will($this->returnValue($empty_violation_list)); $validator->expects($this->at(1))->method('validate')->with($this->entity->getTypedData())->will($this->returnValue($non_empty_violation_list)); $this->typedDataManager->expects($this->exactly(2))->method('getValidator')->will($this->returnValue($validator)); $this->assertSame(0, count($this->entity->validate())); $this->assertSame(1, count($this->entity->validate())); }
/** * @covers ::validate */ public function testValidateHasTermsForVocabularyNoAccess() { $this->forumUninstallValidator->expects($this->once())->method('hasForumNodes')->willReturn(FALSE); $vocabulary = $this->getMock('Drupal\\taxonomy\\VocabularyInterface'); $vocabulary->expects($this->once())->method('label')->willReturn('Vocabulary label'); $vocabulary->expects($this->never())->method('url'); $vocabulary->expects($this->once())->method('access')->willReturn(FALSE); $this->forumUninstallValidator->expects($this->once())->method('getForumVocabulary')->willReturn($vocabulary); $this->forumUninstallValidator->expects($this->once())->method('hasTermsForVocabulary')->willReturn(TRUE); $module = 'forum'; $expected = ['To uninstall Forum, first delete all <em class="placeholder">Vocabulary label</em> terms']; $reasons = $this->forumUninstallValidator->validate($module); $this->assertSame($expected, $this->castSafeStrings($reasons)); }
/** * @covers ::validate */ public function testValidateHasTermsForVocabularyNoAccess() { $this->forumUninstallValidator->expects($this->once())->method('hasForumNodes')->willReturn(FALSE); $vocabulary = $this->getMock('Drupal\\taxonomy\\VocabularyInterface'); $vocabulary->expects($this->once())->method('label')->willReturn('Vocabulary label'); $vocabulary->expects($this->never())->method('url'); $vocabulary->expects($this->once())->method('access')->willReturn(FALSE); $this->forumUninstallValidator->expects($this->once())->method('getForumVocabulary')->willReturn($vocabulary); $this->forumUninstallValidator->expects($this->once())->method('hasTermsForVocabulary')->willReturn(TRUE); $module = 'forum'; $expected = [SafeMarkup::format('To uninstall Forum, first delete all %vocabulary terms', ['%vocabulary' => 'Vocabulary label'])]; $reasons = $this->forumUninstallValidator->validate($module); $this->assertSame($expected, $reasons); }