!C99Shell v. 2.1 [PHP 8 Update] [02.02.2022]!

Software: Apache/2.4.53 (Unix) OpenSSL/1.1.1o PHP/7.4.29 mod_perl/2.0.12 Perl/v5.34.1. PHP/7.4.29 

uname -a: Linux vps-2738122-x 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 

uid=1(daemon) gid=1(daemon) grupos=1(daemon) 

Safe-mode: OFF (not secure)

/opt/apex_tdfonline/php/3ros/shindig/test/social/   drwxr-xr-x
Free 14.57 GB of 61.93 GB (23.52%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     MessageRestTest.php (6.22 KB)      -rwxr-xr-x
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

require_once 'RestBase.php';

/**
 * It is an integration test. Since it's may be used by the specified container implementation.
 * It'd better not to depends on the data in the json DB sample.  
 */
class MessageRestTest extends RestBase {

  private function 
getAllEntities($url) {
    
$sep strpos($url'?') !== false '&' '?';
    
$ret $this->curlRest($url $sep 'startIndex=0&count=1000000''''application/json''GET');
    
$retDecoded json_decode($rettrue);
    
$this->assertTrue($ret != $retDecoded && $ret != null"Invalid json response: $retDecoded");
    return 
$retDecoded['entry'];
  }

  
/**
   * NOTE: If there are lots of messages in the storage this test may take a long time as
   * it retrieves all the message.
   */
  
private function verifyLifeCycle($postData$postDataFormat$randomTitle) {
    
$url '/messages/1/@outbox';
    
    
$cnt count($this->getAllEntities($url));
    
    
// Creates the message.
    
$ret $this->curlRest($url$postData$postDataFormat'POST');
    
$this->assertTrue(empty($ret), "Create message failed. Response: $ret");
    
    
// Gets the message.
    
$messages $this->getAllEntities($url);
    
$this->assertEquals($cnt 1count($messages), "Size of the messages is not right.");
    
$fetchedMessage null;
    foreach (
$messages as $m) {
      if (
$m['title'] == $randomTitle) {
        
$fetchedMessage $m;
      }
    }
    
$this->assertNotNull($fetchedMessage"Couldn't find the created message with title $randomTitle");
    
    
// Deletes the message.
    
$ret $this->curlRest($url '/' urlencode($fetchedMessage['id']), '''application/json''DELETE');
    
$this->assertTrue(empty($ret), "Delete the created message failed. Response: $ret");
    
    
$messages $this->getAllEntities($url$randomTitle);
    
$this->assertEquals($cntcount($messages), "Size of the messages is not right after deletion.");
  }
  
  public function 
testLifeCycleInJson() {
    
$randomTitle "[" rand(02048) . "] message test title.";
    
$postData '{
      "id" : "msgid",
      "recipients" : [2,3],
      "title" : "' 
$randomTitle '",
      "titleId" : "541141091700",
      "body" : "Short message from Joe to some friends",
      "bodyId" : "5491155811231",
      "type" : "privateMessage",
      "status" : "unread"
    }'
;
    
$this->verifyLifeCycle($postData'application/json'$randomTitle);
  }

  public function 
testLifeCycleInXml() {
    
$randomTitle "[" rand(02048) . "] message test title.";
    
$postData '<message xmlns="http://ns.opensocial.org/2008/opensocial">
      <recipient>2</recipient>
      <recipient>3</recipient>
      <title>' 
$randomTitle '</title>
      <id>msgid</id>
      <body>Click <a href="http://app.example.org/invites/{msgid}">here</a> to review your invitation.</body>
    </message>'
;
    
$this->verifyLifeCycle($postData'application/xml'$randomTitle);
  }
  
  public function 
testLifeCycleInAtom() {
    
$randomTitle "[" rand(02048) . "] message test title.";
    
$postData '<entry xmlns="http://www.w3.org/2005/Atom"
             xmlns:osapi="http://opensocial.org/2008/opensocialapi">
      <osapi:recipient>2</osapi:recipient>
      <osapi:recipient>3</osapi:recipient>
      <title>' 
$randomTitle '</title>
      <id>{msgid}</id>
      <link rel="alternate" href="http://app.example.org/invites/{msgid}"/>
      <content>Click <a href="http://app.example.org/invites/{msgid}">here</a> to review your invitation.</content>
    </entry>'
;
    
$this->verifyLifeCycle($postData'application/atom+xml'$randomTitle);
  }
  
  public function 
testMessageCollectionLifeCycle() {
    
$url '/messages/1';
    
// Gets number of message collections in the repository.
    
$cnt count($this->getAllEntities($url));
    
    
// Creates a message collection.
    
$createData = array();
    
$createData['title'] = "[" rand(02048) . "] message collection test title.";
    
$createData['urls'] = array("http://abc.com/abc""http://xyz.com/xyz");
    
$ret $this->curlRest($urljson_encode($createData), 'application/json''POST');
    
    
// Verifies that whether the message collection is created.
    
$retDecoded json_decode($rettrue);
    
$id $retDecoded['entry']['id'];
    
$this->assertEquals($cnt 1count($this->getAllEntities($url)), "Wrong size of the collections. $ret");
    
    
// Updates the created message collection.
    
$newUrls = array("http://123.com/123");
    
$newTitle 'new title';
    
$updateData = array();
    
$updateData['id'] = $id;
    
$updateData['title'] = $newTitle;
    
$updateData['urls'] = $newUrls;
    
    
$ret $this->curlRest($url "/$id"json_encode($updateData), 'application/json''PUT');
    
$this->assertTrue(empty($ret), "Update should return empty. $ret <$id>");

    
$collections $this->getAllEntities($url);
    
$this->assertEquals($cnt 1count($collections), "Wrong size of the collections.");
    
$found false;
    foreach (
$collections as $collection) {
      if (
$collection['id'] == $id) {
        
$this->assertEquals($newTitle$collection['title']);
        
$this->assertEquals($newUrls$collection['urls']);
        
$found true;
      }
    }
    
$this->assertTrue($found"Created message not found.");
    
    
// Deletes the message collection.
    
$ret $this->curlRest($url "/$id"'''application/json''DELETE');
    
    
// Verifies that the message collection is deleted.
    
$this->assertEquals($cntcount($this->getAllEntities($url)), "Wrong size of the collections. $ret");
  }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.1 [PHP 8 Update] [02.02.2022] maintained byC99Shell Github | Generation time: 0.627 ]--