예제 #1
0
파일: ApiInfo.php 프로젝트: alikingravi/itc
 public function __construct(ApiList $list)
 {
     //Loop through each product name
     foreach ($list->getProdName() as $prodName) {
         $getInfoData = ConfigURL::getURL(ApiInfo::$name, $prodName);
         //Check for any errors and store them in $_errors array
         if (isset($getInfoData['error'])) {
             $this->_errors[$prodName] = $getInfoData['error'];
             continue;
         }
         //Initialize $data array
         $data = array();
         //Loop through the product info and store it in the data array.
         //In the case of suppliers, call the sanitize escape function.
         foreach ($getInfoData as $prodKey) {
             foreach ($prodKey as $name => $value) {
                 switch ($name) {
                     case 'suppliers':
                         $data[$name] = escape(implode(', ', $value));
                         break;
                     default:
                         $data[$name] = $value;
                         break;
                 }
             }
         }
         //Store all the data in $_productInfo
         $this->_productInfo[$prodName] = $data;
     }
 }
예제 #2
0
 public function testRefreshFrom()
 {
     // Setup
     $fakeResource = json_encode('{ :data => "fake-data" }');
     $fakeMethod = "fake-api-method";
     $fakeClient = "fake-client";
     $list = new ApiList("ApiResource", [], "invalid", "invalid");
     // Test Should update the apiMethod
     $list->refreshFrom("ApiResource", [$fakeResource], $fakeMethod);
     $this->assertSame($list->apiMethod, $fakeMethod);
     // Test Should update the client
     $list->refreshFrom("ApiResource", [$fakeResource], null, $fakeClient);
     $this->assertSame($list->client, $fakeClient);
     // Test Should clear existing data
     $list->refreshFrom("ApiResource", ["new-data"]);
     $this->assertNull($list->apiMethod);
     $this->assertNull($list->client);
 }