diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/Config/Backend/PriorityTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/Config/Backend/PriorityTest.php new file mode 100644 index 0000000000000..b819dfd343806 --- /dev/null +++ b/app/code/Magento/Sitemap/Test/Unit/Model/Config/Backend/PriorityTest.php @@ -0,0 +1,89 @@ +priorityMock = $this->getMockBuilder(Priority::class) + ->disableOriginalConstructor() + ->setMethods(['getValue']) + ->getMock(); + } + + /** + * Verify before save in chainable + * + * @param string $value + * @dataProvider dataProviderTestBeforeSaveValueCorrect + */ + public function testBeforeSaveIsChainable($value) + { + $this->priorityMock->expects($this->once()) + ->method('getValue') + ->willReturn($value); + + $this->assertSame($this->priorityMock, $this->priorityMock->beforeSave()); + } + + /** + * Verify before save value out of range + * + * @param string $value + * @dataProvider dataProviderTestBeforeSaveValueOutOfRange + */ + public function testBeforeSaveValueOutOfRange($value) + { + $this->priorityMock->expects($this->once()) + ->method('getValue') + ->willReturn($value); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('The priority must be between 0 and 1.'); + + $this->priorityMock->beforeSave(); + } + + /** + * Data provider + * + * @return array + */ + public function dataProviderTestBeforeSaveValueCorrect() + { + return [ + ['0'], ['0.0'], ['0.5'], ['1'] + ]; + } + + /** + * Data provider + * + * @return array + */ + public function dataProviderTestBeforeSaveValueOutOfRange() + { + return [ + ['-1'], ['2'], ['nan'] + ]; + } +}