Beispiel #1
0
 public function testImageInfo()
 {
     $im = \lillockey\Utilities\App\InstanceHolder::image();
     $image_large_jpg = __DIR__ . '/../files/1149112.jpg';
     $image_small_png = __DIR__ . '/../files/1149112.png';
     $large_jpg_info = $im->get_image_file_information($image_large_jpg);
     $this->assertTrue($large_jpg_info instanceof \lillockey\Utilities\App\Containers\ImageFileInformationResults, 'LARGE JPG - Checking if the results are the right class type');
     $this->assertEquals('image/jpeg', $large_jpg_info->type(), 'LARGE JPG - Checking MIME Type');
     $this->assertEquals(9054, $large_jpg_info->size(), 'LARGE JPG - Checking file size');
     $this->assertEquals(184, $large_jpg_info->width(), 'LARGE JPG - Checking width');
     $this->assertEquals(184, $large_jpg_info->height(), 'LARGE JPG - Checking height');
     $this->assertTrue($large_jpg_info->is_jpg(), 'LARGE JPG - Checking image type - is jpg');
     $this->assertFalse($large_jpg_info->is_gif(), 'LARGE JPG - Checking image type - is gif');
     $this->assertFalse($large_jpg_info->is_png(), 'LARGE JPG - Checking image type - is png');
     $this->assertFalse($large_jpg_info->is_bmp(), 'LARGE JPG - Checking image type - is bmp');
     $small_png_info = $im->get_image_file_information($image_small_png);
     $this->assertTrue($small_png_info instanceof \lillockey\Utilities\App\Containers\ImageFileInformationResults, 'SMALL PNG - Checking if the results are the right class type');
     $this->assertEquals('image/png', $small_png_info->type(), 'SMALL PNG - Checking MIME Type');
     $this->assertEquals(1422, $small_png_info->size(), 'SMALL PNG - Checking file size');
     $this->assertEquals(20, $small_png_info->width(), 'SMALL PNG - Checking width');
     $this->assertEquals(20, $small_png_info->height(), 'SMALL PNG - Checking height');
     $this->assertFalse($small_png_info->is_jpg(), 'SMALL PNG - Checking image type - is jpg');
     $this->assertFalse($small_png_info->is_gif(), 'SMALL PNG - Checking image type - is gif');
     $this->assertTrue($small_png_info->is_png(), 'SMALL PNG - Checking image type - is png');
     $this->assertFalse($small_png_info->is_bmp(), 'SMALL PNG - Checking image type - is bmp');
 }
Beispiel #2
0
 public function testDB()
 {
     \lillockey\Utilities\App\InstanceHolder::set_config(new \lillockey\Utilities\Config\FullCustomConfig('localhost', 'root', null, 'test'));
     $db = \lillockey\Utilities\App\InstanceHolder::db();
     //Records
     $records = $db->select_all('test');
     $this->assertTrue(sizeof($records) == 2, "Select all against 2 records");
 }
Beispiel #3
0
 public function testMe()
 {
     $utilities = \lillockey\Utilities\App\InstanceHolder::util();
     $this->assertTrue($utilities instanceof \lillockey\Utilities\App\Utilities, "Utilities loaded");
     $info = $utilities->get_file_information(__FILE__);
     $this->assertTrue($info instanceof \lillockey\Utilities\App\Containers\FileInformationResults, "Loading file type results");
     $this->assertEquals('text/x-php', $info->type(), 'Checking the MIME-type');
     $this->assertEquals(null, $info->recommended_extension(), 'Checking the recommended extension');
 }
 public function testInstanceHolderServer()
 {
     global $_SERVER;
     if (!isset($_SERVER) || !is_array($_SERVER)) {
         $_SERVER = array();
     }
     $expected = \lillockey\Utilities\App\Access\ArrayAccess\ServerArray::class;
     $instance = \lillockey\Utilities\App\InstanceHolder::server();
     $this->assertInstanceOf($expected, $instance, "Server class is not what was expected");
 }
Beispiel #5
0
 public function __construct($json)
 {
     $util = InstanceHolder::util();
     if ($util->is_json($json)) {
         $j_array = json_decode($json, true);
         parent::__construct($j_array);
         $this->json_error = json_last_error();
         $this->json_error_msg = json_last_error_msg();
     } else {
         parent::__construct(new \stdClass());
     }
 }
 public function testValidation()
 {
     $u = \lillockey\Utilities\App\InstanceHolder::util();
     $this->assertTrue($u instanceof \lillockey\Utilities\App\Utilities, "Utilities loaded");
     //Email validation
     $valid_email_mx_okay = "*****@*****.**";
     $valid_email_mx_nokay = "*****@*****.**";
     $invalid_email = "bibbitybobbityboo";
     $this->assertFalse($u->validate_email($valid_email_mx_nokay, true), "Email Validation w/ MX - Good Form - Bad MX");
     $this->assertTrue($u->validate_email($valid_email_mx_nokay, false), "Email Validation w/o MX - Good Form - Bad MX");
     $this->assertTrue($u->validate_email($valid_email_mx_okay, true), "Email Validation w/ MX - Good Form - Good MX");
     $this->assertFalse($u->validate_email($invalid_email, false), "Email Validation w/o MX - Bad Form - Bad MX");
 }
Beispiel #7
0
 /**
  * Checks the image data provided to see if it's actually an image
  * @param $data
  * @return bool|string
  */
 public function validate_image_data(&$data)
 {
     $util = InstanceHolder::util();
     try {
         //This should only break if there's something hostile
         $util->get_data_information($data);
     } catch (\Exception $e) {
         return "There was a problem getting the information";
     }
     //So ... it IS a real thing.
     try {
         //This will break if it isn't an image
         getimagesizefromstring($data);
     } catch (\Exception $e) {
         return "The image wasn't a valid type after all";
     }
     //So ... it's an image ... seems legit
     return true;
 }
 /**
  * Retrieve the value raw
  * @param $key
  * @return mixed
  */
 public function raw($key)
 {
     $util = InstanceHolder::util();
     if ($key === null) {
         $val = null;
     } else {
         $ar = (array) $this;
         $val = $util->getArrayValue($ar, $key);
     }
     return $val;
 }
Beispiel #9
0
 /**
  * Inserts a new record into the given table with columns/values determined by associative array $fields
  * @param string $table
  * @param array $fields
  * @return boolean
  */
 public function insert($table, array $fields)
 {
     $table = $this->config->table($table);
     if ($this->field_name_is_valid($table) === false) {
         return false;
     }
     //Build column/value lists
     $columns = "";
     $values = "";
     $i = 0;
     $submitted_values = array();
     foreach ($fields as $column => $value) {
         if ($this->field_name_is_valid($column) === false) {
             continue;
         }
         if ($value === null) {
             continue;
         }
         if (InstanceHolder::util()->str_left_is($value, '#__')) {
             $function_to_use = substr($value, 3, strlen($value) - 3);
             if ($i == 0) {
                 //If this is the first column/value pair
                 $columns = $column;
                 //Make the columns value = the column name
                 $values = $function_to_use;
                 //Set the value to the premade key
             } else {
                 //If this is any subsequent column/value pair, precede both the value and the column with a ','
                 $columns .= ", {$column}";
                 //Add the column value to the columns list
                 $values .= ", {$function_to_use}";
                 //Add the premade key to the values list
             }
         } else {
             $key = "v{$i}";
             //Make a reusable key
             $submitted_values[$key] = $value;
             //Add the validated column's value into the array to be submitted to the query
             if ($i == 0) {
                 //If this is the first column/value pair
                 $columns = $column;
                 //Make the columns value = the column name
                 $values = ":{$key}";
                 //Set the value to the premade key
             } else {
                 //If this is any subsequent column/value pair, precede both the value and the column with a ','
                 $columns .= ", {$column}";
                 //Add the column value to the columns list
                 $values .= ", :{$key}";
                 //Add the premade key to the values list
             }
         }
         $i++;
         //Next
     }
     //Quick accepted column check.
     if (sizeof($submitted_values) < 1) {
         return false;
     }
     //Create the query
     $query = "INSERT INTO `{$table}` ({$columns}) VALUES ({$values});";
     //Run the query
     $r = $this->execute_query($query, $submitted_values);
     return $r->exec() ? $r->id() : false;
 }
Beispiel #10
0
 public function testWriteToLog()
 {
     $log = \lillockey\Utilities\App\InstanceHolder::log();
     $log->write_to_log('');
 }
Beispiel #11
0
 /**
  * @param $data - the raw data to check
  * @return FileInformationResults
  * @throws \Exception
  */
 public function get_data_information(&$data)
 {
     if (!InstanceHolder::fileinfo_enabled()) {
         throw new \Exception("FileInfo extension not available");
     }
     //Grab the mime type and encoding
     $finfo = finfo_open(FILEINFO_MIME);
     $full_mime = finfo_buffer($finfo, $data);
     $mimex = explode(";", $full_mime);
     $type = $this->getArrayValue($mimex, 0);
     $full_encode = $this->getArrayValue($mimex, 1);
     $full_encode = $full_encode === null ? '' : $full_encode;
     $encodex = explode('=', $full_encode);
     $encoding = $this->getArrayValue($encodex, 1);
     //Grab the file size
     $size = strlen($data);
     //Grab the recommended extension
     $recommended_extension = $this->provide_recommended_file_extension($type);
     return new FileInformationResults($type, $encoding, $recommended_extension, $size);
 }
Beispiel #12
0
 public function get($key)
 {
     return InstanceHolder::string($key);
 }