function asd() { $newClass = new test(); $rows = $newClass->traerAlgoDesdeLaDb(); $viewData = array("id" => 5, "datos" => $rows); View::Show($viewData); }
public function assert_equal_array($expected, $actual, $debug = null) { if ($expected !== $actual) { throw new Kohana_Unit_Test_Exception(sprintf("Expected (%s) %s but received (%s) %s\n Diff: %s", gettype($expected), var_export($expected, true), gettype($actual), var_export($actual, true), test::diff(var_export($expected, true), var_export($actual, true))), $debug); } return $this; }
static function random_tag() { $tag = ORM::factory("tag"); $tag->name = test::lorem_ipsum(rand(2, 4)); // Reload so that ORM coerces all fields into strings. return $tag->save()->reload(); }
public static function getInstance() { if (is_null(self::$_INSTANCE)) { self::$_INSTANCE = new self(); } return self::$_INSTANCE; }
public function testTranslateInto() { $expectedFromTranslate = "MOCKED_RESULT"; $this->mockedTranslator = test::double('Translator', ['translate' => '$expectedFromTranslate']); $result = $this->numbers->translateInto(2, "MOCKED"); $this->assertEquals($expectedFromTranslate, $result, "Incorrect value returned from translateInto()"); }
public function resolve_test() { $album = test::random_album(); $tag = tag::add($album, "tag1")->reload(); $tuple = rest::resolve(rest::url("tag_item", $tag, $album)); $this->assert_equal_array($tag->as_array(), $tuple[0]->as_array()); $this->assert_equal_array($album->as_array(), $tuple[1]->as_array()); }
public function add_user_to_group_test() { $user = test::random_user(); $group = test::random_group(); $group->add($user); $group->save(); $this->assert_true($user->has($group)); }
public function selectById($thepage, $id) { switch ($thepage) { case 'test': $test = new test(); $result = $test->select($_GET['id']); break; default: //$this->common_add($_POST,$thepage); break; } if ($result) { return $result; } else { return NULL; } }
protected function _before() { $this->apigen = test::double('Robo\\Task\\ApiGen\\ApiGen', ['executeCommand' => null, 'output' => new \Symfony\Component\Console\Output\NullOutput()]); if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } $this->testDir = __DIR__ . '..' . DS . '..' . DS . 'data' . DS; $this->testFile = $this->testDir . 'dump.sql'; }
static function factory($x) { if (test::$test) { return test::$test; } else { test::$test = new test($x); return test::$test; } }
public static function getInstance() { if (self::$instance == null) { self::$instance = new test('Singleton1'); } else { echo "Using old class " . self::$instance->myname . "\n"; } return self::$instance; }
public function build_breadcrumbs_for_item_test() { $album = test::random_album(); $item = test::random_photo($album); $expected = array(); $expected[] = Breadcrumb::instance(item::root()->title, item::root()->url("show={$album->id}"))->set_first(); $expected[] = Breadcrumb::instance($album->title, $album->url("show={$item->id}")); $expected[] = Breadcrumb::instance($item->title, $item->url())->set_last(); $this->assert_equal($expected, Breadcrumb::array_from_item_parents($item)); }
private function _get_proxy() { $album = test::random_album(); $photo = test::random_photo($album); access::deny(identity::everybody(), "view_full", $album); access::deny(identity::registered_users(), "view_full", $album); $proxy = ORM::factory("digibug_proxy"); $proxy->uuid = random::hash(); $proxy->item_id = $photo->id; return $proxy->save(); }
public function create_tag_test() { $album = test::random_album(); tag::add($album, "tag1"); $tag = ORM::factory("tag")->where("name", "=", "tag1")->find(); $this->assert_true(1, $tag->count); // Make sure adding the tag again doesn't increase the count tag::add($album, "tag1"); $this->assert_true(1, $tag->reload()->count); tag::add(test::random_album(), "tag1"); $this->assert_true(2, $tag->reload()->count); }
public function deleting_an_item_deletes_its_comments_too_test() { $album = test::random_album(); $comment = ORM::factory("comment"); $comment->item_id = $album->id; $comment->author_id = identity::guest()->id; $comment->guest_name = "test"; $comment->text = "text"; $comment->save(); $album->delete(); $this->assert_false(ORM::factory("comment", $comment->id)->loaded()); }
/** * Validate item config * * @since 0.3.0 * * @access protected * * @param array $data Item config * * @return bool|array Item config array if valid, false if not. */ protected static function validate_config($data) { if (!isset($data['created'])) { $data['created'] = current_time('mysql'); } if (!isset($data['IP'])) { $data['IP'] = ingot_get_ip(); } if (!isset($data['uID'])) { $data['uID'] = get_current_user_id(); } if (!isset($data['slug'])) { $data['slug'] = self::get_slug(); } if (!isset($data['used'])) { $data['used'] = 0; } if (isset($data['click_test_ID'])) { $data['click_test_ID'] = absint($data['click_test_ID']); } else { $data['click_test_ID'] = 0; } if ($data['click_test_ID']) { $test = test::read($data['click_test_ID']); if (!is_array($test)) { $data['click_test_ID'] = 0; } } if (isset($data['click_url'])) { $data['click_url'] = esc_url_raw($data['click_url']); } else { $data['click_url'] = ''; } if (!isset($data['ingot_ID'])) { $data['ingot_ID'] = self::find_ingot_id($data['uID'], $data['IP']); } $data['used'] = (bool) $data['used']; $data['used'] = (int) $data['used']; foreach (self::required() as $key) { if (!isset($data[$key])) { return new \WP_Error('ingot-session-crud-validation-fail', '', array('fail-key' => $key, 'data' => $data)); } } $allowed = array_merge(self::required(), self::needed()); foreach ($data as $key => $datum) { if (!in_array($key, $allowed)) { unset($data[$key]); } elseif (is_numeric($datum)) { $data[$key] = (string) $datum; } } return $data; }
public function generateWithParams() { //the posted value from dimensions is inserted into the session variable $_SESSION["dimension"] = $_POST["dimension"]; $_SESSION["startNrPlants"] = $_POST["startNrPlants"]; $_SESSION["startNrCarnivores"] = $_POST["startNrCarnivore"]; $_SESSION["startNrHerbivores"] = $_POST["startNrHerbivore"]; //If the amount of plants+Carnivores+Herbivores is higher than the amount of squares in the matrix //then there is a message for the matrix being too full. if ($_SESSION["startNrPlants"] + $_SESSION["startNrCarnivores"] + $_SESSION["startNrHerbivores"] >= pow($_SESSION["dimension"], 2)) { include 'Presentation/home.php'; } else { $matrix = new test(); $_SESSION['days'] = $matrix->simulate(); $days = $_SESSION['days']; $_SESSION['daynumber'] = 0; $daynumber = $_SESSION['daynumber']; $day = $days[$daynumber]; include 'Presentation/home.php'; //header("location: ../Presentation/home.php"); } }
public function viewable_test() { $album = test::random_album(); $item = test::random_photo($album); $album->reload(); identity::set_active_user(identity::guest()); // We can see the item when permissions are granted access::allow(identity::everybody(), "view", $album); $this->assert_equal(1, ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); // We can't see the item when permissions are denied access::deny(identity::everybody(), "view", $album); $this->assert_equal(0, ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); }
public function rename_merge_tag_with_same_items_test() { $album = test::random_album(); tag::add($album, "tag1"); tag::add($album, "tag2"); $tag1 = ORM::factory("tag")->where("name", "=", "tag1")->find(); $tag1->name = "tag2"; $tag1->save(); // Tags should be merged $tag1->reload(); $this->assert_equal(1, $tag1->count); $this->assert_true($tag1->has($album)); $this->assert_equal(1, ORM::factory("tag")->count_all()); }
public function cant_view_comments_for_unviewable_items_test() { $album = test::random_album(); $comment = ORM::factory("comment"); $comment->item_id = $album->id; $comment->author_id = identity::admin_user()->id; $comment->text = "text"; $comment->save(); identity::set_active_user(identity::guest()); // We can see the comment when permissions are granted on the album access::allow(identity::everybody(), "view", $album); $this->assert_true(ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all()); // We can't see the comment when permissions are denied on the album access::deny(identity::everybody(), "view", $album); $this->assert_false(ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all()); }
public function change_album_no_csrf_fails_test() { $controller = new Albums_Controller(); $album = test::random_album(); $_POST["name"] = "new name"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; access::allow(identity::everybody(), "edit", item::root()); try { $controller->update($album->id); $this->assert_true(false, "This should fail"); } catch (Exception $e) { // pass $this->assert_same("@todo FORBIDDEN", $e->getMessage()); } }
public function get_ancestors_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); $album2 = test::random_album($album1); $photo2 = test::random_photo($album2); $album1->reload(); $album2->reload(); $root = ORM::factory("item", 1); $restful_root = array("url" => rest::url("item", $root), "entity" => $root->as_restful_array(), "relationships" => rest::relationships("item", $root)); $restful_root["members"] = array(); foreach ($root->children() as $child) { $restful_root["members"][] = rest::url("item", $child); } $request = new stdClass(); $request->params = new stdClass(); $request->params->ancestors_for = rest::url("item", $photo2); $this->assert_equal_array(array($restful_root, array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $album1)), "tags" => array("url" => rest::url("item_tags", $album1), "members" => array())), "members" => array(rest::url("item", $photo1), rest::url("item", $album2))), array("url" => rest::url("item", $album2), "entity" => $album2->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $album2)), "tags" => array("url" => rest::url("item_tags", $album2), "members" => array())), "members" => array(rest::url("item", $photo2))), array("url" => rest::url("item", $photo2), "entity" => $photo2->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $photo2)), "tags" => array("url" => rest::url("item_tags", $photo2), "members" => array())))), items_rest::get($request)); }
<?php // SAMPLE FOR METHOD DELETE() include_once "../generated_classes/class.test.php"; $test = new test(); $test->select(16); $test->delete(16); print "deleted record {$test->id}";
<?php header("Content-type:text/html;Charset=utf-8"); class test { public function __call($name, $arguments) { switch (count($arguments)) { case 2: echo $arguments[0] * $arguments[1], PHP_EOL; break; case 3: echo array_sum($arguments), PHP_EOL; break; default: echo '参数不对', PHP_EOL; break; } } } $a = new test(); $a->make(5); $a->make(5, 6);
<?php class test { public function test() { return ArrayIterator::current(); } } $test = new test(); $test->test(); echo "Done\n";
return array('From PHP:' => $data); } function dump($data) { return print_r($data, true); } function unicode_data() { $returnData = array('word' => mb_convert_encoding('Français', 'UTF-8'), 'suggestion' => array(mb_convert_encoding('Français', 'UTF-8'), mb_convert_encoding('caractères', 'UTF-8'))); return $returnData; } function test1($in) { return $in; } function test2($in) { return $in; } function test3($in) { return $in; } } if (isset($_GET['TEST_CLASS'])) { $t = new test(); var_dump($t->echo_string('test string')); var_dump($t->slow_echo_string('test string')); var_dump($t->error_test('test string')); var_dump($t->multiarg('arg1', 'arg2', 'arg3')); }
public function delete_album_fails_without_permission_test() { $album1 = test::random_album(); access::deny(identity::everybody(), "edit", $album1); identity::set_active_user(identity::guest()); $request->url = rest::url("item", $album1); try { item_rest::delete($request); } catch (Exception $e) { $this->assert_equal("@todo FORBIDDEN", $e->getMessage()); return; } $this->assert_true(false, "Shouldn't get here"); }
public function resize_bad_jpg_test() { // Input is a garbled jpg, output is jpg autofit to 300x300 $input_file = TMPPATH . test::random_name() . ".jpg"; $output_file = TMPPATH . test::random_name() . ".jpg"; $options = array("width" => 300, "height" => 300, "master" => Image::AUTO); file_put_contents($input_file, test::lorem_ipsum(200)); // Should get passed to Image library and throw an exception try { gallery_graphics::resize($input_file, $output_file, $options, null); $this->assert_true(false, "Shouldn't get here"); } catch (Exception $e) { // pass } }
public function illegal_extension_test() { foreach (array("test.php", "test.PHP", "test.php5", "test.php4", "test.pl") as $name) { try { $photo = test::random_photo_unsaved(item::root()); $photo->name = $name; $photo->save(); } catch (ORM_Validation_Exception $e) { $this->assert_equal(array("name" => "illegal_data_file_extension"), $e->validation->errors()); continue; } $this->assert_true(false, "Shouldn't get here"); } }
<?php class test { public $member; function test() { $this->member = 1; register_shutdown_function(array($this, 'destructor')); } function destructor() { print __METHOD__ . "\n"; } function __destruct() { print __METHOD__ . "\n"; } function add() { $this->member += 1; print $this->member . "\n"; } } $t = new test(); $t->add(); $t->add(); echo "Done\n";