assertEquals('', OnString::strrstr('', '')); $this->assertEquals('', OnString::strrstr('hello world to the limit', '')); $this->assertEquals('limit', OnString::strrstr('hello world to the limit', ' ')); $this->assertEquals('', OnString::strrstr('', ' ')); } /** * */ public function testStripFirstCharIf() { $this->assertEquals('', OnString::stripFirstCharIf('', '')); $this->assertEquals('', OnString::stripFirstCharIf('c', '')); $this->assertEquals('', OnString::stripFirstCharIf('c', 'c')); $this->assertEquals('def', OnString::stripFirstCharIf('c', 'cdef')); $this->assertEquals('def', OnString::stripFirstCharIf('c', 'def')); $this->assertEquals('def', OnString::stripFirstCharIf('cd', 'def')); } /** * */ public function testTrimQuote() { $this->assertEquals('', OnString::trimQuote('')); $this->assertEquals('test', OnString::trimQuote('test')); $this->assertEquals(' test ', OnString::trimQuote(' test ')); $this->assertEquals('" test ', OnString::trimQuote('" test ')); $this->assertEquals('" test \'', OnString::trimQuote('" test \'')); $this->assertEquals('\' test "', OnString::trimQuote('\' test "')); $this->assertEquals(' test ', OnString::trimQuote('" test "')); $this->assertEquals(' test ', OnString::trimQuote("' test '")); $this->assertEquals(' te"st ', OnString::trimQuote("' te\"st '")); $this->assertEquals(' te\'st ', OnString::trimQuote("' te'st '")); } /** * */ public function testRemoveNewlinesInNestedExpression() { $this->assertEquals("", OnString::removeNewlinesInNestedExpression("")); $this->assertEquals("test", OnString::removeNewlinesInNestedExpression("test")); $this->assertEquals("{{test}}", OnString::removeNewlinesInNestedExpression("{{test}}")); $this->assertEquals("{{test }}", OnString::removeNewlinesInNestedExpression("{{test\n}}")); $this->assertEquals("{{test two}}", OnString::removeNewlinesInNestedExpression("{{test\ntwo}}")); $this->assertEquals("Pre{{test two}}Post", OnString::removeNewlinesInNestedExpression("Pre{{test\ntwo}}Post")); $this->assertEquals("{{test{{two}}}}", OnString::removeNewlinesInNestedExpression("{{test{{two}}}}")); $this->assertEquals("{{a {{b }}}}", OnString::removeNewlinesInNestedExpression("{{a\n{{b\n}}}}")); $this->assertEquals("{{a b{{c d}}{{e f}} h}}", OnString::removeNewlinesInNestedExpression("{{a\nb{{c\nd}}{{e\nf}}\nh}}")); $this->assertEquals("param1=abc\nsqlInsert = {{SELECT * FROM test WHERE '{{var}}'='true'}}", OnString::removeNewlinesInNestedExpression("param1=abc\nsqlInsert = {{SELECT *\nFROM test\nWHERE '{{var}}'='true'}}")); $this->assertEquals("sqlInsert = {{SELECT * FROM test WHERE '{{var}}'='true'}}\nparam1=abc", OnString::removeNewlinesInNestedExpression("sqlInsert = {{SELECT *\nFROM test\nWHERE '{{var}}'='true'}}\nparam1=abc")); } /** * @throws UserFormException */ public function testExtractFormRecordId() { $this->assertEquals('', OnString::extractFormRecordId('')); $this->assertEquals('', OnString::extractFormRecordId('/')); $this->assertEquals('', OnString::extractFormRecordId('//')); $this->assertEquals(TYPO3_FORM . '=path1' . PHP_EOL, OnString::extractFormRecordId('/path1')); $this->assertEquals(TYPO3_FORM . '=path1' . PHP_EOL, OnString::extractFormRecordId('/path1/')); $this->assertEquals(TYPO3_FORM . '=path1' . PHP_EOL, OnString::extractFormRecordId('path1/')); $expected=TYPO3_RECORD_ID . '=12' . PHP_EOL . TYPO3_FORM . '=path1' . PHP_EOL; $this->assertEquals($expected, OnString::extractFormRecordId('/path1/12')); $expected=TYPO3_RECORD_ID . '=12' . PHP_EOL . TYPO3_FORM . '=path1' . PHP_EOL; $this->assertEquals($expected, OnString::extractFormRecordId('/path1/12/')); $expected=TYPO3_FORM . '=path2' . PHP_EOL . TYPO3_REST_PATH . '=path1/12'. PHP_EOL; $this->assertEquals($expected, OnString::extractFormRecordId('/path1/12/path2')); $expected=TYPO3_RECORD_ID . '=34' . PHP_EOL . TYPO3_FORM . '=path2' . PHP_EOL . TYPO3_REST_PATH . '=path1/12'. PHP_EOL; $this->assertEquals($expected, OnString::extractFormRecordId('/path1/12/path2/34')); } /** * @expectedException \qfq\UserFormException * */ public function testExtractFormRecordId_1() { # An alnum string is requested as path $this->assertEquals('', OnString::extractFormRecordId('/%')); } /** * @expectedException \qfq\UserFormException * */ public function testExtractFormRecordId_2() { # A numerical value is requested as id $this->assertEquals('', OnString::extractFormRecordId('/path1/path2')); } /** * @expectedException \qfq\UserFormException * */ public function testRemoveNewlinesInNestedExpression_missingClosing_1() { $str = OnString::removeNewlinesInNestedExpression("Hi! {{Test "); } /** * @expectedException \qfq\UserFormException * */ public function testRemoveNewlinesInNestedExpression_missingClosing_2() { $str = OnString::removeNewlinesInNestedExpression("Hi! {{Test}"); } /** * @expectedException \qfq\UserFormException * */ public function testRemoveNewlinesInNestedExpression_missingClosing_3() { $str = OnString::removeNewlinesInNestedExpression("Hi! {{Test {{var }}"); } /** * @expectedException \qfq\UserFormException * */ public function testRemoveNewlinesInNestedExpression_missingOpening_1() { $str = OnString::removeNewlinesInNestedExpression("}}"); } /** * @expectedException \qfq\UserFormException * */ public function testRemoveNewlinesInNestedExpression_missingOpening_2() { $str = OnString::removeNewlinesInNestedExpression("{}}"); } /** * @expectedException \qfq\UserFormException * */ public function testRemoveNewlinesInNestedExpression_missingOpening_3() { $str = OnString::removeNewlinesInNestedExpression("{{Test}}}}"); } }