123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\Stdlib\Test\Unit;
- use \Magento\Framework\Stdlib\StringUtils;
- /**
- * Magento\Framework\Stdlib\StringUtilsTest test case
- */
- class StringUtilsTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Framework\Stdlib\StringUtils
- */
- protected $_string;
- protected function setUp()
- {
- $this->_string = new StringUtils();
- }
- /**
- * @covers \Magento\Framework\Stdlib\StringUtils::split
- */
- public function testStrSplit()
- {
- $this->assertEquals([], $this->_string->split(''));
- $this->assertEquals(['1', '2', '3', '4'], $this->_string->split('1234', 1));
- $this->assertEquals(['1', '2', ' ', '3', '4'], $this->_string->split('12 34', 1, false, true));
- $this->assertEquals(
- ['12345', '123', '12345', '6789'],
- $this->_string->split('12345 123 123456789', 5, true, true)
- );
- $this->assertEquals(
- ['1234', '5', '123', '1234', '5678', '9'],
- $this->_string->split('12345 123 123456789', 4, true, true)
- );
- }
- /**
- * @covers \Magento\Framework\Stdlib\StringUtils::splitInjection
- */
- public function testSplitInjection()
- {
- $string = '1234567890';
- $this->assertEquals('1234 5678 90', $this->_string->splitInjection($string, 4));
- }
- /**
- * @covers \Magento\Framework\Stdlib\StringUtils::cleanString
- */
- public function testCleanString()
- {
- $string = '12345';
- $this->assertEquals($string, $this->_string->cleanString($string));
- }
- public function testSubstr()
- {
- $this->assertSame('tring', $this->_string->substr('string', 1));
- }
- public function testStrrev()
- {
- $this->assertSame('0987654321', $this->_string->strrev('1234567890'));
- $this->assertSame('', $this->_string->strrev(''));
- }
- /**
- * @covers \Magento\Framework\Stdlib\StringUtils::strpos
- */
- public function testStrpos()
- {
- $this->assertEquals(1, $this->_string->strpos('123', 2));
- }
- /**
- * @param string $testString
- * @param string $expected
- *
- * @dataProvider upperCaseWordsDataProvider
- */
- public function testUpperCaseWords($testString, $expected)
- {
- $actual = $this->_string->upperCaseWords($testString);
- $this->assertEquals($expected, $actual);
- }
- /**
- * @return array
- */
- public function upperCaseWordsDataProvider()
- {
- return [
- ['test test2', 'Test_Test2'],
- ['test_test2', 'Test_Test2'],
- ['test_test2 test3', 'Test_Test2_Test3']
- ];
- }
- /**
- * @param string $testString
- * @param string $sourceSeparator
- * @param string $destinationSeparator
- * @param string $expected
- *
- * @dataProvider upperCaseWordsWithSeparatorsDataProvider
- */
- public function testUpperCaseWordsWithSeparators($testString, $sourceSeparator, $destinationSeparator, $expected)
- {
- $actual = $this->_string->upperCaseWords($testString, $sourceSeparator, $destinationSeparator);
- $this->assertEquals($expected, $actual);
- }
- /**
- * @return array
- */
- public function upperCaseWordsWithSeparatorsDataProvider()
- {
- return [['test test2_test3\test4|test5', '|', '\\', 'Test\Test2_test3\test4\Test5']];
- }
- }
|