How to use __toString method of are class

Best Mockery code snippet using are.__toString

EncoderTest.php

Source:EncoderTest.php Github

copy

Full Screen

...102 . " 1 0 1 1 1 0 1 0 1 0 0 0 1 0 1 0 1 1 1 0 1\n"103 . " 1 0 0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 0 0 1 1\n"104 . " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1\n"105 . ">>\n";106 $this->assertEquals($expected, $qrCode->__toString());107 }108 public function testSimpleUtf8Eci()109 {110 $qrCode = Encoder::encode('hello', new ErrorCorrectionLevel(ErrorCorrectionLevel::H), 'utf-8');111 $expected = "<<\n"112 . " mode: BYTE\n"113 . " ecLevel: H\n"114 . " version: 1\n"115 . " maskPattern: 3\n"116 . " matrix:\n"117 . " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\n"118 . " 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 1\n"119 . " 1 0 1 1 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 1\n"120 . " 1 0 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1\n"121 . " 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1\n"122 . " 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1\n"123 . " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n"124 . " 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0\n"125 . " 0 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0 1 0 0 0 0\n"126 . " 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 1 1 1 0\n"127 . " 0 1 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 1 1 1 1\n"128 . " 1 1 0 0 1 0 0 1 1 0 0 1 1 1 1 0 1 0 1 1 0\n"129 . " 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 0 0\n"130 . " 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1\n"131 . " 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 1 0 0 1 0 0\n"132 . " 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 1 1 1 1 0 1\n"133 . " 1 0 1 1 1 0 1 0 0 1 0 0 0 0 1 1 0 0 0 0 0\n"134 . " 1 0 1 1 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 0\n"135 . " 1 0 1 1 1 0 1 0 1 1 0 0 0 1 0 0 1 0 0 0 0\n"136 . " 1 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 1 1 0\n"137 . " 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 1 1 0 0 0 0\n"138 . ">>\n";139 $this->assertEquals($expected, $qrCode->__toString());140 }141 public function testAppendModeInfo()142 {143 $bits = new BitArray();144 $this->methods['appendModeInfo']->invoke(null, new Mode(Mode::NUMERIC), $bits);145 $this->assertEquals(' ...X', $bits->__toString());146 }147 public function testAppendLengthInfo()148 {149 // 1 letter (1/1), 10 bits.150 $bits = new BitArray();151 $this->methods['appendLengthInfo']->invoke(152 null,153 1,154 Version::getVersionForNumber(1),155 new Mode(Mode::NUMERIC),156 $bits157 );158 $this->assertEquals(' ........ .X', $bits->__toString());159 // 2 letters (2/1), 11 bits.160 $bits = new BitArray();161 $this->methods['appendLengthInfo']->invoke(162 null,163 2,164 Version::getVersionForNumber(10),165 new Mode(Mode::ALPHANUMERIC),166 $bits167 );168 $this->assertEquals(' ........ .X.', $bits->__toString());169 // 255 letters (255/1), 16 bits.170 $bits = new BitArray();171 $this->methods['appendLengthInfo']->invoke(172 null,173 255,174 Version::getVersionForNumber(27),175 new Mode(Mode::BYTE),176 $bits177 );178 $this->assertEquals(' ........ XXXXXXXX', $bits->__toString());179 // 512 letters (1024/2), 12 bits.180 $bits = new BitArray();181 $this->methods['appendLengthInfo']->invoke(182 null,183 512,184 Version::getVersionForNumber(40),185 new Mode(Mode::KANJI),186 $bits187 );188 $this->assertEquals(' ..X..... ....', $bits->__toString());189 }190 public function testAppendBytes()191 {192 // Should use appendNumericBytes.193 // 1 = 01 = 0001 in 4 bits.194 $bits = new BitArray();195 $this->methods['appendBytes']->invoke(196 null,197 '1',198 new Mode(Mode::NUMERIC),199 $bits,200 Encoder::DEFAULT_BYTE_MODE_ECODING201 );202 $this->assertEquals(' ...X', $bits->__toString());203 // Should use appendAlphaNumericBytes.204 // A = 10 = 0xa = 001010 in 6 bits.205 $bits = new BitArray();206 $this->methods['appendBytes']->invoke(207 null,208 'A',209 new Mode(Mode::ALPHANUMERIC),210 $bits,211 Encoder::DEFAULT_BYTE_MODE_ECODING212 );213 $this->assertEquals(' ..X.X.', $bits->__toString());214 // Should use append8BitBytes.215 // 0x61, 0x62, 0x63216 $bits = new BitArray();217 $this->methods['appendBytes']->invoke(218 null,219 'abc',220 new Mode(Mode::BYTE),221 $bits,222 Encoder::DEFAULT_BYTE_MODE_ECODING223 );224 $this->assertEquals(' .XX....X .XX...X. .XX...XX', $bits->__toString());225 // Should use appendKanjiBytes.226 // 0x93, 0x5f227 $bits = new BitArray();228 $this->methods['appendBytes']->invoke(229 null,230 "\x93\x5f",231 new Mode(Mode::KANJI),232 $bits,233 Encoder::DEFAULT_BYTE_MODE_ECODING234 );235 $this->assertEquals(' .XX.XX.. XXXXX', $bits->__toString());236 // Lower letters such as 'a' cannot be encoded in alphanumeric mode.237 $this->setExpectedException(238 'BaconQrCode\Exception\WriterException',239 'Invalid alphanumeric code'240 );241 $this->methods['appendBytes']->invoke(242 null,243 "a",244 new Mode(Mode::ALPHANUMERIC),245 $bits,246 Encoder::DEFAULT_BYTE_MODE_ECODING247 );248 }249 public function testTerminateBits()250 {251 $bits = new BitArray();252 $this->methods['terminateBits']->invoke(null, 0, $bits);253 $this->assertEquals('', $bits->__toString());254 $bits = new BitArray();255 $this->methods['terminateBits']->invoke(null, 1, $bits);256 $this->assertEquals(' ........', $bits->__toString());257 $bits = new BitArray();258 $bits->appendBits(0, 3);259 $this->methods['terminateBits']->invoke(null, 1, $bits);260 $this->assertEquals(' ........', $bits->__toString());261 $bits = new BitArray();262 $bits->appendBits(0, 5);263 $this->methods['terminateBits']->invoke(null, 1, $bits);264 $this->assertEquals(' ........', $bits->__toString());265 $bits = new BitArray();266 $bits->appendBits(0, 8);267 $this->methods['terminateBits']->invoke(null, 1, $bits);268 $this->assertEquals(' ........', $bits->__toString());269 $bits = new BitArray();270 $this->methods['terminateBits']->invoke(null, 2, $bits);271 $this->assertEquals(' ........ XXX.XX..', $bits->__toString());272 $bits = new BitArray();273 $bits->appendBits(0, 1);274 $this->methods['terminateBits']->invoke(null, 3, $bits);275 $this->assertEquals(' ........ XXX.XX.. ...X...X', $bits->__toString());276 }277 public function testGetNumDataBytesAndNumEcBytesForBlockId()278 {279 // Version 1-H.280 list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 26, 9, 1, 0);281 $this->assertEquals(9, $numDataBytes);282 $this->assertEquals(17, $numEcBytes);283 // Version 3-H. 2 blocks.284 list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 70, 26, 2, 0);285 $this->assertEquals(13, $numDataBytes);286 $this->assertEquals(22, $numEcBytes);287 list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 70, 26, 2, 1);288 $this->assertEquals(13, $numDataBytes);289 $this->assertEquals(22, $numEcBytes);290 // Version 7-H. (4 + 1) blocks.291 list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 196, 66, 5, 0);292 $this->assertEquals(13, $numDataBytes);293 $this->assertEquals(26, $numEcBytes);294 list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 196, 66, 5, 4);295 $this->assertEquals(14, $numDataBytes);296 $this->assertEquals(26, $numEcBytes);297 // Version 40-H. (20 + 61) blocks.298 list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 3706, 1276, 81, 0);299 $this->assertEquals(15, $numDataBytes);300 $this->assertEquals(30, $numEcBytes);301 list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 3706, 1276, 81, 20);302 $this->assertEquals(16, $numDataBytes);303 $this->assertEquals(30, $numEcBytes);304 list($numDataBytes, $numEcBytes) = $this->methods['getNumDataBytesAndNumEcBytesForBlockId']->invoke(null, 3706, 1276, 81, 80);305 $this->assertEquals(16, $numDataBytes);306 $this->assertEquals(30, $numEcBytes);307 }308 public function testInterleaveWithEcBytes()309 {310 $dataBytes = SplFixedArray::fromArray(array(32, 65, 205, 69, 41, 220, 46, 128, 236), false);311 $in = new BitArray();312 foreach ($dataBytes as $dataByte) {313 $in->appendBits($dataByte, 8);314 }315 $outBits = $this->methods['interleaveWithEcBytes']->invoke(null, $in, 26, 9, 1);316 $expected = SplFixedArray::fromArray(array(317 // Data bytes.318 32, 65, 205, 69, 41, 220, 46, 128, 236,319 // Error correction bytes.320 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61,321 ), false);322 $out = $outBits->toBytes(0, count($expected));323 $this->assertEquals($expected, $out);324 }325 public function testAppendNumericBytes()326 {327 // 1 = 01 = 0001 in 4 bits.328 $bits = new BitArray();329 $this->methods['appendNumericBytes']->invoke(null, '1', $bits);330 $this->assertEquals(' ...X', $bits->__toString());331 // 12 = 0xc = 0001100 in 7 bits.332 $bits = new BitArray();333 $this->methods['appendNumericBytes']->invoke(null, '12', $bits);334 $this->assertEquals(' ...XX..', $bits->__toString());335 // 123 = 0x7b = 0001111011 in 10 bits.336 $bits = new BitArray();337 $this->methods['appendNumericBytes']->invoke(null, '123', $bits);338 $this->assertEquals(' ...XXXX. XX', $bits->__toString());339 // 1234 = "123" + "4" = 0001111011 + 0100 in 14 bits.340 $bits = new BitArray();341 $this->methods['appendNumericBytes']->invoke(null, '1234', $bits);342 $this->assertEquals(' ...XXXX. XX.X..', $bits->__toString());343 // Empty344 $bits = new BitArray();345 $this->methods['appendNumericBytes']->invoke(null, '', $bits);346 $this->assertEquals('', $bits->__toString());347 }348 public function testAppendAlphanumericBytes()349 {350 $bits = new BitArray();351 $this->methods['appendAlphanumericBytes']->invoke(null, 'A', $bits);352 $this->assertEquals(' ..X.X.', $bits->__toString());353 $bits = new BitArray();354 $this->methods['appendAlphanumericBytes']->invoke(null, 'AB', $bits);355 $this->assertEquals(' ..XXX..X X.X', $bits->__toString());356 $bits = new BitArray();357 $this->methods['appendAlphanumericBytes']->invoke(null, 'ABC', $bits);358 $this->assertEquals(' ..XXX..X X.X..XX. .', $bits->__toString());359 // Empty360 $bits = new BitArray();361 $this->methods['appendAlphanumericBytes']->invoke(null, '', $bits);362 $this->assertEquals('', $bits->__toString());363 // Invalid data364 $this->setExpectedException('BaconQrCode\Exception\WriterException', 'Invalid alphanumeric code');365 $bits = new BitArray();366 $this->methods['appendAlphanumericBytes']->invoke(null, 'abc', $bits);367 }368 public function testAppend8BitBytes()369 {370 // 0x61, 0x62, 0x63371 $bits = new BitArray();372 $this->methods['append8BitBytes']->invoke(null, 'abc', $bits, Encoder::DEFAULT_BYTE_MODE_ECODING);373 $this->assertEquals(' .XX....X .XX...X. .XX...XX', $bits->__toString());374 // Empty375 $bits = new BitArray();376 $this->methods['append8BitBytes']->invoke(null, '', $bits, Encoder::DEFAULT_BYTE_MODE_ECODING);377 $this->assertEquals('', $bits->__toString());378 }379 public function testAppendKanjiBytes()380 {381 // Numbers are from page 21 of JISX0510:2004382 $bits = new BitArray();383 $this->methods['appendKanjiBytes']->invoke(null, "\x93\x5f", $bits);384 $this->assertEquals(' .XX.XX.. XXXXX', $bits->__toString());385 $this->methods['appendKanjiBytes']->invoke(null, "\xe4\xaa", $bits);386 $this->assertEquals(' .XX.XX.. XXXXXXX. X.X.X.X. X.', $bits->__toString());387 }388 public function testGenerateEcBytes()389 {390 // Numbers are from http://www.swetake.com/qr/qr3.html and391 // http://www.swetake.com/qr/qr9.html392 $dataBytes = SplFixedArray::fromArray(array(32, 65, 205, 69, 41, 220, 46, 128, 236), false);393 $ecBytes = $this->methods['generateEcBytes']->invoke(null, $dataBytes, 17);394 $expected = SplFixedArray::fromArray(array(42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61), false);395 $this->assertEquals($expected, $ecBytes);396 $dataBytes = SplFixedArray::fromArray(array(67, 70, 22, 38, 54, 70, 86, 102, 118, 134, 150, 166, 182, 198, 214), false);397 $ecBytes = $this->methods['generateEcBytes']->invoke(null, $dataBytes, 18);398 $expected = SplFixedArray::fromArray(array(175, 80, 155, 64, 178, 45, 214, 233, 65, 209, 12, 155, 117, 31, 140, 214, 27, 187), false);399 $this->assertEquals($expected, $ecBytes);400 // High-order zero coefficient case....

Full Screen

Full Screen

FormTest.php

Source:FormTest.php Github

copy

Full Screen

...22 23 public function testFormCanBeRendered()24 {25 $form = new Form([Form::TEXT]);26 $this->assertRegExp('/^<form/', $form->__toString());27 $this->assertRegExp('/<input[\s]+type="text"[\s]+>/', $form->__toString());28 $this->assertRegExp('/<\/form>$/', $form->__toString());29 }30 31 public function testExceptionIsThrownIfNoElementsAreProvided()32 {33 $this->setExpectedException(34 Form\Exception::Class,35 '',36 Form\Exception::NO_ELEMENT_PROVIDED37 );38 $form = new Form([]);39 }40 41 public function testFormMethodDefaultsToPost()42 {43 $form = new Form([Form::TEXT]);44 $this->assertContains('method="post"', $form->__toString());45 }46 47 public function testMethodCanBeSetToGet()48 {49 $form = new Form([Form::TEXT], 'get');50 $this->assertContains('method="get"', $form->__toString());51 }52 53 public function testExceptionIsThrownIfMethodIsNotPostOrGet()54 {55 $this->setExpectedException(56 Form\Exception::Class,57 '',58 Form\Exception::INVALID_METHOD_PROVIDED59 );60 new Form([Form::TEXT], 'invalid');61 }62 63 public function testNoTargetIsSetByDefault()64 {65 $form = new Form([Form::TEXT], 'post');66 $this->assertNotContains('target', $form->__toString());67 }68 69 public function testFormTargetCanBeSet()70 {71 $form = new Form([Form::TEXT], 'post', '/example/path');72 $this->assertContains('target="/example/path"', $form->__toString());73 }74 75 public function testExceptionIsThrownIfProvidedTargetIsNotAString()76 {77 $this->setExpectedException(78 Form\Exception::Class,79 '',80 Form\Exception::NON_STRING_PROVIDED_AS_TARGET81 );82 new Form([Form::TEXT], 'post', true);83 }84 85 public function testMultipleElementsCanBeProvidedAndAreRendered()86 {87 $form = new Form([88 Form::TEXT,89 Form::SUBMIT90 ]);91 $this->assertRegExp(92 '/<input(?:[\s]+[^\s>]*)*?[\s]+type="text"(?:[\s]+[^\s>]*)*?>/',93 $form->__toString()94 );95 $this->assertRegExp(96 '/<input(?:[\s]+[^\s>]*)*?[\s]+type="submit"(?:[\s]+[^\s>]*)*?>/',97 $form->__toString()98 );99 }100 101 public function testElementKeyMustBeEqualToAClassConstant()102 {103 $this->setExpectedException(104 Form\Exception::Class,105 '',106 Form\Exception::INVALID_ELEMENT_KEY_PROVIDED107 );108 new Form([109 Form::TEXT,110 999111 ]);112 }113 114 public function testElementKeyCanBeProvidedInsideArray()115 {116 $form = new Form([117 ['element' => Form::TEXT]118 ]);119 $this->assertRegExp(120 '/<input(?:[\s]+[^\s>]*)*?[\s]+type="text"(?:[\s]+[^\s>]*)*?>/',121 $form->__toString()122 );123 }124 125 public function testArrayElementDefinitionMustIncludeElementKey()126 {127 $this->setExpectedException(128 Form\Exception::Class,129 '',130 Form\Exception::INVALID_ELEMENT_DEFINITION131 );132 new Form([133 ['notElement' => Form::TEXT]134 ]);135 }136 137 public function testExceptionIsThrownIfElementKeyIsNotAnIntegerOrArray()138 {139 $this->setExpectedException(140 Form\Exception::Class,141 '',142 Form\Exception::INVALID_ELEMENT_DEFINITION143 );144 new Form([145 Form::TEXT => true146 ]);147 }148 149 public function testLabelCanBeCreatedForElementAndForAttributeIsSetCorrectly()150 {151 $form = new Form([152 [153 'element' => Form::TEXT,154 'label' => 'My Label',155 'id' => 'my-element'156 ]157 ]);158 $this->assertRegExp(159 '/<input(?:[\s]+[^\s>]*)*?[\s]+(?:type="text"[\s]+id="my-element"|'.160 'id="my-element"[\s]+type="text")(?:[\s]+[^\s>]*)*?>/',161 $form->__toString()162 );163 $this->assertRegExp(164 '/<label(?:[\s]+[^\s>]*)*?[\s]+for="my-element"'.165 '(?:[\s]+[^\s>]*)*?>[\s]*My Label[\s]*<\/label>/',166 $form->__toString()167 );168 }169 170 public function testLabelIsShownDirectlyBeforeRelatedInput()171 {172 $form = new Form([173 [174 'element' => Form::TEXT,175 'label' => 'My Label',176 'id' => 'my-element'177 ]178 ]);179 $this->assertRegExp(180 '/<label[^>]+>[^<]+<\/label>[\s]*<input[^>]+>/',181 $form->__toString()182 );183 }184 185 public function testExceptionIsThrownIfLabelIsDeclaredButNoIDIsDeclared()186 {187 $this->setExpectedException(188 Form\Exception::Class,189 '',190 Form\Exception::MISSING_VALUE_IN_ELEMENT_DECLARATION191 );192 $form = new Form([193 [194 'element' => Form::TEXT,195 'label' => 'My Label'196 ]197 ]);198 }199 200 public function testExceptionIsThrownIfLabelIsNotAString()201 {202 $this->setExpectedException(203 Form\Exception::Class,204 '',205 Form\Exception::INVALID_VALUE_IN_ELEMENT_DECLARATION206 );207 $form = new Form([208 [209 'element' => Form::TEXT,210 'label' => ['My Label'],211 'id' => 'my-element'212 ]213 ]);214 }215 216 public function testExceptionIsThrownIfContentIsProvidedForASelfClosingElementType()217 {218 $this->setExpectedException(219 Form\Exception::Class,220 '',221 Form\Exception::CONTENT_PROVIDED_FOR_SELF_CLOSING_TAG222 );223 new Form([224 [225 'element' => Form::TEXT,226 'content' => 'I\'m the content'227 ]228 ]);229 }230 231 public function testElementCanBeURL()232 {233 $form = new Form([Form::URL]);234 $this->assertRegExp('/<input[\s]+type="url"[\s]+>/', $form->__toString());235 }236 237 public function testElementCanBeTelephoneNumber()238 {239 $form = new Form([Form::TEL]);240 $this->assertRegExp('/<input[\s]+type="tel"[\s]+>/', $form->__toString());241 }242 243 public function testElementCanBeEmailAddress()244 {245 $form = new Form([Form::EMAIL]);246 $this->assertRegExp('/<input[\s]+type="email"[\s]+>/', $form->__toString());247 }248 249 public function testElementCanBeSearchField()250 {251 $form = new Form([Form::SEARCH]);252 $this->assertRegExp('/<input[\s]+type="search"[\s]+>/', $form->__toString());253 }254 255 public function testElementCanBeNumber()256 {257 $form = new Form([Form::NUMBER]);258 $this->assertRegExp('/<input[\s]+type="number"[\s]+>/', $form->__toString());259 }260 261 public function testElementCanBeRange()262 {263 $form = new Form([Form::RANGE]);264 $this->assertRegExp('/<input[\s]+type="range"[\s]+>/', $form->__toString());265 }266 267 public function testElementCanBeDateTimeLocal()268 {269 $form = new Form([Form::DATE_TIME_LOCAL]);270 $this->assertRegExp('/<input[\s]+type="datetime-local"[\s]+>/', $form->__toString());271 }272 273 public function testElementCanBeDate()274 {275 $form = new Form([Form::DATE]);276 $this->assertRegExp('/<input[\s]+type="date"[\s]+>/', $form->__toString());277 }278 279 public function testElementCanBeTime()280 {281 $form = new Form([Form::TIME]);282 $this->assertRegExp('/<input[\s]+type="time"[\s]+>/', $form->__toString());283 }284 285 public function testElementCanBeWeek()286 {287 $form = new Form([Form::WEEK]);288 $this->assertRegExp('/<input[\s]+type="week"[\s]+>/', $form->__toString());289 }290 291 public function testElementCanBeMonth()292 {293 $form = new Form([Form::MONTH]);294 $this->assertRegExp('/<input[\s]+type="month"[\s]+>/', $form->__toString());295 }296 297 public function testElementCanBeColor()298 {299 $form = new Form([Form::COLOR]);300 $this->assertRegExp('/<input[\s]+type="color"[\s]+>/', $form->__toString());301 }302 303 public function testElementCanBeTextArea()304 {305 $form = new Form([Form::TEXTAREA]);306 $this->assertRegExp('/<textarea[\s]*>[\s]*<\/textarea>/', $form->__toString());307 }308 309 public function testTextAreaElementCanContainContent()310 {311 $form = new Form([312 [313 'element' => Form::TEXTAREA,314 'content' => 'I\'m the content'315 ]316 ]);317 $this->assertRegExp('/<textarea[\s]*>[\s]*I\'m the content[\s]*<\/textarea>/', $form->__toString());318 }319 320 public function testElementCanBeSelectAndOptionsAreRendered()321 {322 $form = new Form([323 [324 'element' => Form::SELECT,325 'options' => ['One', 'Two']326 ]327 ]);328 $this->assertRegExp(329 '/<select[\s]*>[\s]*<option[\s]*>[\s]*One[\s]*<\/option>[\s]*'.330 '<option[\s]*>[\s]*Two[\s]*<\/option>[\s]*<\/select>/',331 $form->__toString()332 );333 }334 335 public function testSelectElementCanRenderOptionsWithProvidedValues()336 {337 $form = new Form([338 [339 'element' => Form::SELECT,340 'options' => [341 'one' => 'Uno',342 'two' => 'Dos'343 ]344 ]345 ]);346 $this->assertRegExp(347 '/<select[\s]*>[\s]*<option[\s]*value="one"[\s]*>[\s]*Uno[\s]*<\/option>[\s]*'.348 '<option[\s]*value="two"[\s]*>[\s]*Dos[\s]*<\/option>[\s]*<\/select>/',349 $form->__toString()350 );351 }352 353 public function testDataListCanBeRenderedForInputElementAndIdAndListAttributesAreIncluded()354 {355 $form = new Form([356 [357 'element' => Form::TEXT,358 'datalist' => [359 'id' => 'my-list',360 'options' => ['One', 'Two']361 ]362 ]363 ]);364 $this->assertRegExp(365 '/<input[\s]+(?:list="my-list"[\s]+type="text"|type="text"[\s]+list="my-list")[\s]*>/',366 $form->__toString()367 );368 $this->assertRegExp(369 '/<datalist[\s]+id="my-list"[\s]*>[\s]*<option[\s]+value="One"[\s]*>[\s]*'.370 '<option[\s]+value="Two"[\s]*>[\s]*<\/datalist>/',371 $form->__toString()372 );373 }374 375 public function testDataListCanBeProvidedWithNoIdAndARandomOneIsGenerated()376 {377 $form = new Form([378 [379 'element' => Form::TEXT,380 'datalist' => ['One', 'Two']381 ]382 ]);383 $this->assertRegExp(384 '/<input[\s]+(?:list="list-[a-z]{6}"[\s]+type="text"|type="text"[\s]+' .385 'list="list-[a-z]{6}")[\s]*>/',386 $form->__toString()387 );388 $this->assertRegExp(389 '/<datalist[\s]+id="list-[a-z]{6}"[\s]*>[\s]*<option[\s]+value="One"[\s]*>[\s]*' .390 '<option[\s]+value="Two"[\s]*>[\s]*<\/datalist>/',391 $form->__toString()392 );393 preg_match(394 '/<input[\s]+(?:list="(list-[a-z]{6})"[\s]+type="text"|type="text"[\s]+' .395 'list="(list-[a-z]{6})")[\s]*>/',396 $form,397 $inputMatch398 );399 preg_match(400 '/<datalist[\s]+id="(list-[a-z]{6})"[\s]*>[\s]*<option[\s]+value="One"[\s]*>[\s]*' .401 '<option[\s]+value="Two"[\s]*>[\s]*<\/datalist>/',402 $form,403 $dataListMatch404 );405 $this->assertTrue(406 $dataListMatch[1] == $inputMatch[1] ||407 $dataListMatch[1] == $inputMatch[2]408 );409 }410 411 public function testElementCanBeDeclaredWithAutoFocus()412 {413 $form = new Form([414 [415 'element' => Form::TEXT,416 'autofocus' => true417 ]418 ]);419 $this->assertRegExp(420 '/<input[\s]+(?:type="text"[\s]+autofocus|autofocus[\s]*type="text")[\s]*>/',421 $form->__toString()422 );423 }424 425 public function testOnlyOneElementCanBeDeclaredAutoFocus()426 {427 $this->setExpectedException(428 Form\Exception::Class,429 '',430 Form\Exception::DUPLICATE_AUTOFOCUS431 );432 new Form([433 Form::TEXT,434 [435 'element' => Form::TEXT,436 'autofocus' => true437 ],438 [439 'element' => Form::TEXT,440 'autofocus' => true441 ]442 ]);443 }444 445 public function testUnrecognisedDefinitionKeyIsUsedAsAttribute()446 {447 $form = new Form([448 [449 'element' => Form::TEXT,450 'required' => true,451 'anything' => true452 ]453 ]);454 $this->assertRegExp(455 '/<input[\s]+[\sa-z="-]*required(?:[\s]+[\sa-z="-]*)?>/',456 $form->__toString()457 );458 $this->assertRegExp(459 '/<input[\s]+[\sa-z="-]*anything(?:[\s]+[\sa-z="-]*)?>/',460 $form->__toString()461 );462 }463 464 public function testUnrecognisedAttributeCanContainSingleValue()465 {466 $form = new Form([467 [468 'element' => Form::TEXT,469 'class' => 'some-class'470 ]471 ]);472 $this->assertRegExp(473 '/<input[\s]+[\sa-z="-]*class="some-class"(?:[\s]+[\sa-z="-]*)?>/',474 $form->__toString()475 );476 }477 478 public function testUnrecognisedAttributeCanContainMultipleValues()479 {480 $form = new Form([481 [482 'element' => Form::TEXT,483 'class' => ['class-one', 'class-two']484 ]485 ]);486 $this->assertRegExp(487 '/<input[\s]+[\sa-z="-]*class="(?:class-one class-two|class-two class-one)' .488 '"(?:[\s]+[\sa-z="-]*)?>/',489 $form->__toString()490 );491 }492 493 // @todo button - http://reference.sitepoint.com/html/button494 // @todo enctype - http://reference.sitepoint.com/html/form495 496}...

Full Screen

Full Screen

ToStringTrait.php

Source:ToStringTrait.php Github

copy

Full Screen

1<?php2namespace Drupal\Component\Utility;3/**4 * Wraps __toString in a trait to avoid some fatals.5 */6trait ToStringTrait {7 /**8 * Implements the magic __toString() method.9 */10 public function __toString() {11 try {12 return (string) $this->render();13 }14 catch (\Exception $e) {15 // User errors in __toString() methods are considered fatal in the Drupal16 // error handler.17 trigger_error(get_class($e) . ' thrown while calling __toString on a ' . static::class . ' object in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage(), E_USER_ERROR);18 // In case we are using another error handler that did not fatal on the19 // E_USER_ERROR, we terminate execution. However, for test purposes allow20 // a return value.21 return $this->_die();22 }23 }24 /**25 * For test purposes, wrap die() in an overridable method.26 */27 protected function _die() {28 die();29 }30 /**31 * Renders the object as a string.32 *33 * @return string|object34 * The rendered string or an object implementing __toString().35 */36 abstract public function render();37}...

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$are = new are();2echo $are;3$are = new are();4echo $are;5$are = new are();6echo $are;7$are = new are();8echo $are;9$are = new are();10echo $are;11$are = new are();12echo $are;13$are = new are();14echo $are;15$are = new are();16echo $are;17$are = new are();18echo $are;19$are = new are();20echo $are;21$are = new are();22echo $are;23$are = new are();24echo $are;25$are = new are();26echo $are;27$are = new are();28echo $are;29$are = new are();30echo $are;31$are = new are();32echo $are;33$are = new are();34echo $are;35$are = new are();36echo $are;

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$obj = new are();2echo $obj;3$obj = new are();4$obj();5$obj = new are();6$obj->test();7are::test();8$obj = new are();9echo $obj->test;10$obj = new are();11$obj->test = 'hello';12$obj = new are();13isset($obj->test);14$obj = new are();15unset($obj->test);16$obj = new are();17serialize($obj);18$obj = new are();19$ser = serialize($obj);20unserialize($ser);21$obj = new are();22$obj2 = clone $obj;23$obj = new are();24var_dump($obj);25$obj = new are();26eval('$obj2 = ' . var_export($obj, true) . ';');27$obj = new are();28$obj();29$obj = new are();30$obj->test();31are::test();32$obj = new are();33echo $obj->test;34$obj = new are();35$obj->test = 'hello';

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$myobj = new are();2echo $myobj;3$myobj = new are();4echo $myobj;5$myobj = new are();6echo $myobj;7$myobj = new are();8echo $myobj;9$myobj = new are();10echo $myobj;11$myobj = new are();12echo $myobj;13$myobj = new are();14echo $myobj;15$myobj = new are();16echo $myobj;17$myobj = new are();18echo $myobj;19$myobj = new are();20echo $myobj;21$myobj = new are();22echo $myobj;23$myobj = new are();24echo $myobj;25$myobj = new are();26echo $myobj;27$myobj = new are();28echo $myobj;29$myobj = new are();30echo $myobj;31$myobj = new are();32echo $myobj;33$myobj = new are();34echo $myobj;

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$area = new Area(5, 10);2echo $area;3$area = new Area(5, 10);4echo $area;5$area = new Area(5, 10);6echo $area;7$area = new Area(5, 10);8echo $area;9$area = new Area(5, 10);10echo $area;11$area = new Area(5, 10);12echo $area;13$area = new Area(5, 10);14echo $area;15$area = new Area(5, 10);16echo $area;17$area = new Area(5, 10);18echo $area;19$area = new Area(5, 10);20echo $area;21$area = new Area(5, 10);22echo $area;23$area = new Area(5, 10);24echo $area;25$area = new Area(5, 10);26echo $area;27$area = new Area(5, 10);28echo $area;29$area = new Area(5, 10);30echo $area;

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$obj = new are();2echo $obj;3$obj = new are();4echo $obj->get();5$obj = new are();6echo $obj->get();7$obj = new are();8echo $obj->get();

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$obj = new area(5, 5);2echo $obj;3$obj = new area(5, 5);4echo $obj;5$obj = new area(5, 5);6echo $obj;7$obj = new area(5, 5);8echo $obj;9$obj = new area(5, 5);10echo $obj;11$obj = new area(5, 5);12echo $obj;13$obj = new area(5, 5);14echo $obj;15$obj = new area(5, 5);16echo $obj;17$obj = new area(5, 5);18echo $obj;19$obj = new area(5, 5);20echo $obj;21$obj = new area(5, 5);22echo $obj;23$obj = new area(5, 5);24echo $obj;25$obj = new area(5, 5);26echo $obj;27$obj = new area(5, 5);28echo $obj;29$obj = new area(5, 5);30echo $obj;31$obj = new area(5, 5);32echo $obj;

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$are = new Are();2echo $are;3$are = new Are();4echo $are;5$are = new Are();6echo $are;7$are = new Are();8echo $are;9$are = new Are();10echo $are;11$are = new Are();12echo $are;13$are = new Are();14echo $are;15$are = new Are();16echo $are;17$are = new Are();18echo $are;19$are = new Are();20echo $are;21$are = new Are();22echo $are;23$are = new Are();24echo $are;25$are = new Are();26echo $are;27$are = new Are();28echo $are;

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$are = new are();2echo $are;3class are {4 public function __toString() {5 return "This is __toString method";6 }7}8$are = new are();9echo $are;10Recommended Posts: PHP | __toString() method11PHP | __toString() Magic Method12PHP | __set() Magic Method13PHP | __get() Magic Method14PHP | __isset() Magic Method15PHP | __unset() Magic Method16PHP | __sleep() Magic Method17PHP | __wakeup() Magic Method18PHP | __call() Magic Method19PHP | __callStatic() Magic Method20PHP | __invoke() Magic Method21PHP | __set_state() Magic Method22PHP | __clone() Magic Method23PHP | __debugInfo() Magic Method24PHP | __autoload() Magic Method25PHP | __construct() Magic Method26PHP | __destruct() Magic Method27PHP | __call() Magic Method28PHP | __callStatic() Magic Method29PHP | __get() Magic Method30PHP | __set() Magic Method31PHP | __isset() Magic Method32PHP | __unset() Magic Method33PHP | __sleep() Magic Method34PHP | __wakeup() Magic Method35PHP | __toString() Magic Method36PHP | __invoke() Magic Method37PHP | __autoload() Magic Method38PHP | __debugInfo() Magic Method39PHP | __clone() Magic Method40PHP | __set_state() Magic Method41PHP | __destruct() Magic Method42PHP | __construct() Magic Method43PHP | __call() Magic Method44PHP | __callStatic() Magic Method45PHP | __get() Magic Method46PHP | __set() Magic Method47PHP | __isset() Magic Method48PHP | __unset() Magic Method49PHP | __sleep() Magic Method50PHP | __wakeup() Magic Method51PHP | __toString() Magic Method52PHP | __invoke() Magic Method53PHP | __autoload() Magic Method54PHP | __debugInfo() Magic Method55PHP | __clone() Magic Method

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful