public function testAuthenticatedPUT()
    {
        $comment1 = $this->objFromFixture('SoapModelAccessTest_Comment', 'comment1');
        $comment1ID = $comment1->ID;
        // test wrong details
        $c = $this->getTestSoapConnection();
        $updateXML = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
\t\t<SoapModelAccessTest_Comment>
\t\t\t<ID>{$comment1ID}</ID>
\t\t\t<Name>Jimmy</Name>
\t\t</SoapModelAccessTest_Comment>\t\t\t
XML;
        $soapResponse = $c->putXML("SoapModelAccessTest_Comment", $comment1->ID, null, $updateXML, '*****@*****.**', 'wrongpassword');
        $this->assertEquals('<error type="authentication" code="401">Unauthorized</error>', $soapResponse);
        // Check that the details weren't saved
        $c = $this->getTestSoapConnection();
        $soapResponse = $c->getXML("SoapModelAccessTest_Comment", $comment1->ID, null, '*****@*****.**', 'editor');
        $responseArr = Convert::xml2array($soapResponse);
        $this->assertEquals($comment1->ID, $responseArr['ID']);
        $this->assertEquals('Joe', $responseArr['Name']);
        // Now do an update with the right password
        $soapResponse = $c->putXML("SoapModelAccessTest_Comment", $comment1->ID, null, $updateXML, '*****@*****.**', 'editor');
        // Check that the details were saved
        $c = $this->getTestSoapConnection();
        $soapResponse = $c->getXML("SoapModelAccessTest_Comment", $comment1->ID, null, '*****@*****.**', 'editor');
        $responseArr = Convert::xml2array($soapResponse);
        $this->assertEquals($comment1->ID, $responseArr['ID']);
        $this->assertEquals('Jimmy', $responseArr['Name']);
    }
Exemplo n.º 2
0
	/**
	 * Create a summary of the content. This will either be the first paragraph, or the first $maxWords 
	 * words, whichever is shorter
	 */
	public function Summary( $maxWords = 50 ) {
		// split the string into tags and words
		$parts = Convert::xml2array( $this->value );
		
		// store any unmatched tags
		$tagStack = array();
		
		$pIndex = 0;
		
		// find the first paragraph tag
		for( $i = 0; $i < count( $parts ); $i++ )
			if( strpos( $parts[$i], '<p' ) === 0 ) {
				$pIndex = $i;
				break;
			}
				
		$summary = '';
		$words = 0;
		
		// create the summary, keeping track of opening and closing tags
		while( $words <= $maxWords && $pIndex < count( $parts ) ) {
			if( $parts[$pIndex] == '</p>' ) {
				$summary .= $parts[$pIndex];
				break;
			}
			elseif( preg_match( '/<\/(\w+)>/', $parts[$pIndex], $endTag ) && $endTag[1] == substr( $tagStack[count($tagStack) - 1], 1, strlen( $endTag[1] ) ) ) {
				array_pop( $tagStack );
				$words++;
				$summary .= $parts[$pIndex++];
			} elseif( preg_match( '/^<\w+/', $parts[$pIndex] ) ) {
				array_push( $tagStack, $parts[$pIndex] );
				$words++;
				$summary .= $parts[$pIndex++];
			} else
				$summary .= $parts[$pIndex++] . ' ';
		}
		
		// Tags that shouldn't be closed
		$noClose = array("br", "img");
		
		// make sure that the summary is well formed XHTML by closing tags
		while( $openTag = array_pop( $tagStack ) ) {
			preg_match( '/^<(\w+)\s+/', $openTag, $tagName );
			if(sizeof($tagName) > 0) {
			    if(!in_array($tagName[1], $noClose)) {
					$summary .= "</{$tagName[1]}>";
			    }
			}
		}
		
		return $summary;
	}
    /**
     * Tests {@link Convert::xml2array()}
     */
    public function testXML2Array()
    {
        // Ensure an XML file at risk of entity expansion can be avoided safely
        $inputXML = <<<XML
<?xml version="1.0"?>
<!DOCTYPE results [<!ENTITY long "SOME_SUPER_LONG_STRING">]>
<results>
    <result>Now include &long; lots of times to expand the in-memory size of this XML structure</result>
    <result>&long;&long;&long;</result>
</results>
XML;
        try {
            Convert::xml2array($inputXML, true);
        } catch (Exception $ex) {
        }
        $this->assertTrue(isset($ex) && $ex instanceof InvalidArgumentException && $ex->getMessage() === 'XML Doctype parsing disabled');
        // Test without doctype validation
        $expected = array('result' => array("Now include SOME_SUPER_LONG_STRING lots of times to expand the in-memory size of this XML structure", array('long' => array(array('long' => 'SOME_SUPER_LONG_STRING'), array('long' => 'SOME_SUPER_LONG_STRING'), array('long' => 'SOME_SUPER_LONG_STRING')))));
        $result = Convert::xml2array($inputXML, false, true);
        $this->assertEquals($expected, $result);
        $result = Convert::xml2array($inputXML, false, false);
        $this->assertEquals($expected, $result);
    }
Exemplo n.º 4
0
 public function convertStringToArray($strData)
 {
     return Convert::xml2array($strData);
 }
 public function testApiAccessWithPOST()
 {
     $url = "/api/v1/RestfulServerTest_AuthorRating";
     $data = array('Rating' => '42', 'WriteProtectedField' => 'haxx0red');
     $response = Director::test($url, $data, null, 'POST');
     // Assumption: XML is default output
     $responseArr = Convert::xml2array($response->getBody());
     $this->assertEquals($responseArr['Rating'], 42);
     $this->assertNotEquals($responseArr['WriteProtectedField'], 'haxx0red');
 }
 /**
  * Manages the 'return' and 'cancel' replies
  */
 function complete()
 {
     $this->extend("EwayPayment_Handler_completion_start");
     if (isset($_REQUEST['code']) && ($code = $_REQUEST['code'])) {
         $params = explode('-', $code);
         if (count($params) == 2) {
             $payment = EwayPayment::get()->byID(intval($params[0]));
             if ($payment && $payment->AuthorisationCode == $params[1]) {
                 if (isset($_REQUEST['AccessPaymentCode'])) {
                     $url = $payment->EwayConfirmationURL($_REQUEST['AccessPaymentCode']);
                     $response = file_get_contents($url);
                     if ($response) {
                         $response = Convert::xml2array($response);
                         if (isset($response['ResponseCode']) && $response['ResponseCode'] == '00') {
                             $payment->Status = 'Success';
                         } else {
                             $payment->Status = 'Failure';
                         }
                     } else {
                         $payment->Status = 'Failure';
                     }
                     $payment->write();
                     $payment->redirectToOrder();
                 }
             }
         }
     }
 }