本文整理汇总了PHP中Convert::nl2os方法的典型用法代码示例。如果您正苦于以下问题:PHP Convert::nl2os方法的具体用法?PHP Convert::nl2os怎么用?PHP Convert::nl2os使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Convert
的用法示例。
在下文中一共展示了Convert::nl2os方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInheritedGetManiplatedData
/**
* Test getManipulatedData on subclassed dataobjects
*/
public function testInheritedGetManiplatedData()
{
$list = GridFieldSortableHeaderTest_TeamGroup::get();
$config = new GridFieldConfig_RecordEditor();
$gridField = new GridField('testfield', 'testfield', $list, $config);
$state = $gridField->State->GridFieldSortableHeader;
$compontent = $gridField->getConfig()->getComponentByType('GridFieldSortableHeader');
// Test that inherited dataobjects will work correctly
$state->SortColumn = 'Cheerleader.Hat.Colour';
$state->SortDirection = 'asc';
$relationListA = $compontent->getManipulatedData($gridField, $list);
$relationListAsql = Convert::nl2os($relationListA->sql(), ' ');
// Assert that all tables are joined properly
$this->assertContains('FROM "GridFieldSortableHeaderTest_Team"', $relationListAsql);
$this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_TeamGroup" ' . 'ON "GridFieldSortableHeaderTest_TeamGroup"."ID" = "GridFieldSortableHeaderTest_Team"."ID"', $relationListAsql);
$this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_Cheerleader" ' . 'ON "GridFieldSortableHeaderTest_Cheerleader"."ID" = "GridFieldSortableHeaderTest_Team"."CheerleaderID"', $relationListAsql);
$this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_CheerleaderHat" ' . 'ON "GridFieldSortableHeaderTest_CheerleaderHat"."ID" = "GridFieldSortableHeaderTest_Cheerleader"."HatID"', $relationListAsql);
// Test sorting is correct
$this->assertEquals(array('Cologne', 'Auckland', 'Wellington', 'Melbourne'), $relationListA->column('City'));
$state->SortDirection = 'desc';
$relationListAdesc = $compontent->getManipulatedData($gridField, $list);
$this->assertEquals(array('Melbourne', 'Wellington', 'Auckland', 'Cologne'), $relationListAdesc->column('City'));
// Test subclasses of tables
$state->SortColumn = 'CheerleadersMom.Hat.Colour';
$state->SortDirection = 'asc';
$relationListB = $compontent->getManipulatedData($gridField, $list);
$relationListBsql = $relationListB->sql();
// Assert that subclasses are included in the query
$this->assertContains('FROM "GridFieldSortableHeaderTest_Team"', $relationListBsql);
$this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_TeamGroup" ' . 'ON "GridFieldSortableHeaderTest_TeamGroup"."ID" = "GridFieldSortableHeaderTest_Team"."ID"', $relationListBsql);
// Joined tables are joined basetable first
$this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_Cheerleader" ' . 'ON "GridFieldSortableHeaderTest_Cheerleader"."ID" = "GridFieldSortableHeaderTest_Team"."CheerleadersMomID"', $relationListBsql);
// Then the basetable of the joined record is joined to the specific subtable
$this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_Mom" ' . 'ON "GridFieldSortableHeaderTest_Cheerleader"."ID" = "GridFieldSortableHeaderTest_Mom"."ID"', $relationListBsql);
$this->assertContains('LEFT JOIN "GridFieldSortableHeaderTest_CheerleaderHat" ' . 'ON "GridFieldSortableHeaderTest_CheerleaderHat"."ID" = "GridFieldSortableHeaderTest_Cheerleader"."HatID"', $relationListBsql);
// Test sorting is correct
$this->assertEquals(array('Cologne', 'Auckland', 'Wellington', 'Melbourne'), $relationListB->column('City'));
$state->SortDirection = 'desc';
$relationListBdesc = $compontent->getManipulatedData($gridField, $list);
$this->assertEquals(array('Melbourne', 'Wellington', 'Auckland', 'Cologne'), $relationListBdesc->column('City'));
}
示例2: langArrayCodeForEntitySpec
/**
* Input for langArrayCodeForEntitySpec() should be suitable for insertion
* into single-quoted strings, so needs to be escaped already.
*
* @param string $entity The entity name, e.g. CMSMain.BUTTONSAVE
*/
public function langArrayCodeForEntitySpec($entityFullName, $entitySpec, $locale)
{
$php = '';
$eol = PHP_EOL;
$entityParts = explode('.', $entityFullName);
if (count($entityParts) > 1) {
// templates don't have a custom namespace
$entity = array_pop($entityParts);
// namespace might contain dots, so we implode back
$namespace = implode('.', $entityParts);
} else {
user_error("i18nTextCollector::langArrayCodeForEntitySpec(): Wrong entity format for {$entityFullName} with values " . var_export($entitySpec, true), E_USER_WARNING);
return false;
}
$value = $entitySpec[0];
$comment = isset($entitySpec[1]) ? addcslashes($entitySpec[1], '\'') : null;
$php .= '$lang[\'' . $locale . '\'][\'' . $namespace . '\'][\'' . $entity . '\'] = ';
$php .= count($entitySpec) == 1 ? var_export($entitySpec[0], true) : var_export($entitySpec, true);
$php .= ";{$eol}";
// Normalise linebreaks due to fix var_export output
return Convert::nl2os($php, $eol);
}
示例3: testNL2OS
/**
* Tests {@link Convert::nl2os()}
*/
public function testNL2OS()
{
foreach (array("\r\n", "\r", "\n") as $nl) {
// Base case: no action
$this->assertEqualsQuoted("Base case", Convert::nl2os("Base case", $nl));
// Mixed formats
$this->assertEqualsQuoted("Test{$nl}Text{$nl}Is{$nl}{$nl}Here{$nl}.", Convert::nl2os("Test\rText\r\nIs\n\rHere\r\n.", $nl));
// Test that multiple runs are non-destructive
$expected = "Test{$nl}Text{$nl}Is{$nl}{$nl}Here{$nl}.";
$this->assertEqualsQuoted($expected, Convert::nl2os($expected, $nl));
// Check repeated sequence behaves correctly
$expected = "{$nl}{$nl}{$nl}{$nl}{$nl}{$nl}{$nl}{$nl}";
$input = "\r\r\n\r\r\n\n\n\n\r";
$this->assertEqualsQuoted($expected, Convert::nl2os($input, $nl));
}
}
示例4: testNewTemplateTranslation
/**
* See @i18nTestModule.ss for the template that is being used for this test
* */
public function testNewTemplateTranslation()
{
global $lang;
$oldLocale = i18n::get_locale();
i18n::set_locale('en_US');
i18n::get_translator('core')->getAdapter()->addTranslation(array('i18nTestModule.NEWMETHODSIG' => 'TRANS New _t method signature test', 'i18nTestModule.INJECTIONS' => 'TRANS Hello {name} {greeting}. But it is late, {goodbye}'), 'en_US');
$viewer = new SSViewer('i18nTestModule');
$parsedHtml = Convert::nl2os($viewer->process(new ArrayData(array('TestProperty' => 'TestPropertyValue'))));
$this->assertContains(Convert::nl2os("Hello Mark welcome. But it is late, bye\n"), $parsedHtml, "Testing fallback to the translation default (but using the injection array)");
$this->assertContains(Convert::nl2os("TRANS Hello Paul good you are here. But it is late, see you\n"), $parsedHtml, "Testing entity, default string and injection array");
$this->assertContains(Convert::nl2os("TRANS Hello Cat meow. But it is late, meow\n"), $parsedHtml, "Testing a translation with just entity and injection array");
//test injected calls
$this->assertContains(Convert::nl2os("TRANS Hello " . Director::absoluteBaseURL() . " " . i18n::get_locale() . ". But it is late, global calls\n"), $parsedHtml, "Testing a translation with just entity and injection array, but with global variables injected in");
i18n::set_locale($oldLocale);
}
示例5: testYamlWriter
/**
* @todo Should be in a separate test suite, but don't want to duplicate setup logic
*/
public function testYamlWriter()
{
$writer = new i18nTextCollector_Writer_RailsYaml();
$entities = array('Level1.Level2.EntityName' => array('Text', 'Context'), 'Level1.OtherEntityName' => array('Other Text', 'Other Context'), 'Level1.BoolTest' => array('True'), 'Level1.FlagTest' => array('No'), 'Level1.TextTest' => array('Maybe'));
$yaml = <<<YAML
de:
Level1:
Level2:
EntityName: Text
OtherEntityName: 'Other Text'
BoolTest: 'True'
FlagTest: 'No'
TextTest: Maybe
YAML;
$this->assertEquals($yaml, Convert::nl2os($writer->getYaml($entities, 'de')));
}
示例6: testSendHTML
/**
* Test HTML messages
*/
public function testSendHTML()
{
$mailer = new MailerTest_MockMailer();
// Test with default encoding
$testMessageHTML = "<p>The majority of the <i>answers</i> so far are saying that private methods are " . "implementation details which don't (<a href=\"http://www.google.com\">or at least shouldn't</a>) " . "matter so long as the public interface is well-tested & working</p> " . "<p>That's absolutely correct if your only purpose for testing is to guarantee that the " . "public interface works.</p>";
$testMessagePlain = Convert::xml2raw($testMessageHTML);
$this->assertTrue(stripos($testMessagePlain, '&#') === false);
list($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress) = $mailer->sendHTML('<email@silverstripe.com>', 'tom@jones <tom@silverstripe.com>', "What is the <purpose> of testing?", $testMessageHTML, null, array('CC' => 'admin@silverstripe.com', 'bcc' => 'andrew@thing.com'));
$this->assertEquals('email@silverstripe.com', $to);
$this->assertEquals('=?UTF-8?B?V2hhdCBpcyB0aGUgPHB1cnBvc2U+IG9mIHRlc3Rpbmc/?=', $subjectEncoded);
$this->assertEquals('=?UTF-8?B?' . base64_encode('What is the <purpose> of testing?') . '?=', $subjectEncoded);
$this->assertEquals(Convert::nl2os(<<<PHP
This is a multi-part message in MIME format.
------=_NextPart_000000000000
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
The majority of the answers so far are saying that private methods are impl=
ementation details which don't (or at least shouldn't[http://www.google.com=
]) matter so long as the public interface is well-tested & working=0A=0A=0A=
=0AThat's absolutely correct if your only purpose for testing is to guarant=
ee that the public interface works.
------=_NextPart_000000000000
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">=0A<HTML><HEA=
D>=0A<META http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-=
8">=0A<STYLE type=3D"text/css"></STYLE>=0A=0A</HEAD>=0A<BODY bgColor=3D"#ff=
ffff">=0A<p>The majority of the <i>answers</i> so far are saying that priva=
te methods are implementation details which don't (<a href=3D"http://ww=
w.google.com">or at least shouldn't</a>) matter so long as the public i=
nterface is well-tested & working</p> <p>That's absolutely correct =
if your only purpose for testing is to guarantee that the public interface =
works.</p>=0A</BODY>=0A</HTML>
------=_NextPart_000000000000--
PHP
), Convert::nl2os($this->normaliseDivisions($fullBody)));
// Check that the messages exist in the output
$this->assertTrue(stripos($fullBody, quoted_printable_encode($testMessagePlain)) !== false);
$this->assertEquals(<<<PHP
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_NextPart_000000000000"
Content-Transfer-Encoding: 7bit
From: tomjones <tom@silverstripe.com>
X-Mailer: SilverStripe Mailer - version 2006.06.21
X-Priority: 3
Bcc: andrew@thing.com
Cc: admin@silverstripe.com
PHP
, Convert::nl2os($this->normaliseDivisions($headersEncoded)));
$this->assertEquals('tom@silverstripe.com', $bounceAddress);
// Test override bounce email and alternate encoding
$mailer->setBounceEmail('bounce@silverstripe.com');
$mailer->setMessageEncoding('base64');
list($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress) = $mailer->sendHTML('<email@silverstripe.com>', 'tom@jones <tom@silverstripe.com>', "What is the <purpose> of testing?", $testMessageHTML, null, array('CC' => 'admin@silverstripe.com', 'bcc' => 'andrew@thing.com'));
$this->assertEquals('bounce@silverstripe.com', $bounceAddress);
$this->assertEquals(<<<PHP
This is a multi-part message in MIME format.
------=_NextPart_000000000000
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
VGhlIG1ham9yaXR5IG9mIHRoZSBhbnN3ZXJzIHNvIGZhciBhcmUgc2F5aW5n
IHRoYXQgcHJpdmF0ZSBtZXRob2RzIGFyZSBpbXBsZW1lbnRhdGlvbiBkZXRh
aWxzIHdoaWNoIGRvbid0IChvciBhdCBsZWFzdCBzaG91bGRuJ3RbaHR0cDov
L3d3dy5nb29nbGUuY29tXSkgbWF0dGVyIHNvIGxvbmcgYXMgdGhlIHB1Ymxp
YyBpbnRlcmZhY2UgaXMgd2VsbC10ZXN0ZWQgJiB3b3JraW5nCgoKClRoYXQn
cyBhYnNvbHV0ZWx5IGNvcnJlY3QgaWYgeW91ciBvbmx5IHB1cnBvc2UgZm9y
IHRlc3RpbmcgaXMgdG8gZ3VhcmFudGVlIHRoYXQgdGhlIHB1YmxpYyBpbnRl
cmZhY2Ugd29ya3Mu
------=_NextPart_000000000000
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBU
cmFuc2l0aW9uYWwvL0VOIj4KPEhUTUw+PEhFQUQ+CjxNRVRBIGh0dHAtZXF1
aXY9IkNvbnRlbnQtVHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0
PXV0Zi04Ij4KPFNUWUxFIHR5cGU9InRleHQvY3NzIj48L1NUWUxFPgoKPC9I
RUFEPgo8Qk9EWSBiZ0NvbG9yPSIjZmZmZmZmIj4KPHA+VGhlIG1ham9yaXR5
IG9mIHRoZSA8aT5hbnN3ZXJzPC9pPiBzbyBmYXIgYXJlIHNheWluZyB0aGF0
IHByaXZhdGUgbWV0aG9kcyBhcmUgaW1wbGVtZW50YXRpb24gZGV0YWlscyB3
aGljaCBkb24mIzM5O3QgKDxhIGhyZWY9Imh0dHA6Ly93d3cuZ29vZ2xlLmNv
bSI+b3IgYXQgbGVhc3Qgc2hvdWxkbiYjMzk7dDwvYT4pIG1hdHRlciBzbyBs
b25nIGFzIHRoZSBwdWJsaWMgaW50ZXJmYWNlIGlzIHdlbGwtdGVzdGVkICZh
bXA7IHdvcmtpbmc8L3A+IDxwPlRoYXQmIzM5O3MgYWJzb2x1dGVseSBjb3Jy
ZWN0IGlmIHlvdXIgb25seSBwdXJwb3NlIGZvciB0ZXN0aW5nIGlzIHRvIGd1
YXJhbnRlZSB0aGF0IHRoZSBwdWJsaWMgaW50ZXJmYWNlIHdvcmtzLjwvcD4K
PC9CT0RZPgo8L0hUTUw+
//.........这里部分代码省略.........