|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Sitemap\Test\Unit\Model\Config\Backend; |
| 8 | + |
| 9 | +use Magento\Sitemap\Model\Config\Backend\Priority; |
| 10 | +use PHPUnit\Framework\MockObject\MockObject; |
| 11 | + |
| 12 | +/** |
| 13 | + * Tests for @see Priority |
| 14 | + */ |
| 15 | +class PriorityTest extends \PHPUnit\Framework\TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var Priority|MockObject |
| 19 | + */ |
| 20 | + private $priorityMock; |
| 21 | + |
| 22 | + /** |
| 23 | + * @inheritDoc |
| 24 | + */ |
| 25 | + protected function setUp() |
| 26 | + { |
| 27 | + $this->priorityMock = $this->getMockBuilder(Priority::class) |
| 28 | + ->disableOriginalConstructor() |
| 29 | + ->setMethods(['getValue']) |
| 30 | + ->getMock(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Verify before save in chainable |
| 35 | + * |
| 36 | + * @param string $value |
| 37 | + * @dataProvider dataProviderTestBeforeSaveValueCorrect |
| 38 | + */ |
| 39 | + public function testBeforeSaveIsChainable($value) |
| 40 | + { |
| 41 | + $this->priorityMock->expects($this->once()) |
| 42 | + ->method('getValue') |
| 43 | + ->willReturn($value); |
| 44 | + |
| 45 | + $this->assertSame($this->priorityMock, $this->priorityMock->beforeSave()); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Verify before save value out of range |
| 50 | + * |
| 51 | + * @param string $value |
| 52 | + * @dataProvider dataProviderTestBeforeSaveValueOutOfRange |
| 53 | + */ |
| 54 | + public function testBeforeSaveValueOutOfRange($value) |
| 55 | + { |
| 56 | + $this->priorityMock->expects($this->once()) |
| 57 | + ->method('getValue') |
| 58 | + ->willReturn($value); |
| 59 | + |
| 60 | + $this->expectException(\Exception::class); |
| 61 | + $this->expectExceptionMessage('The priority must be between 0 and 1.'); |
| 62 | + |
| 63 | + $this->priorityMock->beforeSave(); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Data provider |
| 68 | + * |
| 69 | + * @return array |
| 70 | + */ |
| 71 | + public function dataProviderTestBeforeSaveValueCorrect() |
| 72 | + { |
| 73 | + return [ |
| 74 | + ['0'], ['0.0'], ['0.5'], ['1'] |
| 75 | + ]; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Data provider |
| 80 | + * |
| 81 | + * @return array |
| 82 | + */ |
| 83 | + public function dataProviderTestBeforeSaveValueOutOfRange() |
| 84 | + { |
| 85 | + return [ |
| 86 | + ['-1'], ['2'], ['nan'] |
| 87 | + ]; |
| 88 | + } |
| 89 | +} |
0 commit comments