public function testUserRelationshipReturnsModel() { $meta = Factory::create('PostMeta', ['meta_key' => 'pal_user_id', 'meta_value' => 1]); Factory::create('User', ['id' => 1]); $user = $meta->user; assertThat($user, is(anInstanceof('User'))); }
public function testAppendMetaAndContentText() { $this->pagedResult->appendMetaText(self::META_TEXT); $this->pagedResult->appendContentText(self::CONTENT_TEXT); assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET + strlen(self::CONTENT_TEXT))); assertThat($this->pagedResult->getText(), is(self::META_TEXT . self::CONTENT_TEXT)); }
function test() { $username = new FormKit\Widget\TextInput('username', array('label' => 'Username')); $username->value('default')->maxlength(10)->minlength(3)->size(20); $password = new FormKit\Widget\PasswordInput('password', array('label' => 'Password')); $remember = new FormKit\Widget\CheckboxInput('remember', array('label' => 'Remember me')); $remember->value(12); $remember->check(); $widgets = new FormKit\WidgetCollection(); ok($widgets); $widgets->add($username); $widgets->add($password); $widgets->add($remember); // get __get method is($username, $widgets->username); is($password, $widgets->password); is($username, $widgets->get('username')); ok($widgets->render('username')); ok(is_array($widgets->getJavascripts())); ok(is_array($widgets->getStylesheets())); is(3, $widgets->size()); $widgets->remove($username); is(2, $widgets->size()); unset($widgets['password']); is(1, $widgets->size()); }
/** * Return an array of actor identifiers * * @return array */ protected static function _findActorIdentifiers(KServiceInterface $container) { $components = $container->get('repos://admin/components.component')->getQuery()->enabled(true)->fetchSet(); $components = array_unique($container->get('repos://admin/components.component')->fetchSet()->component); $identifiers = array(); foreach ($components as $component) { $path = JPATH_SITE . '/components/' . $component . '/domains/entities'; if (!file_exists($path)) { continue; } //get all the files $files = (array) JFolder::files($path); //convert com_<Component> to ['com','<Name>'] $parts = explode('_', $component); $identifier = new KServiceIdentifier('com:' . substr($component, strpos($component, '_') + 1)); $identifier->path = array('domain', 'entity'); foreach ($files as $file) { $identifier->name = substr($file, 0, strpos($file, '.')); try { if (is($identifier->classname, 'ComActorsDomainEntityActor')) { $identifiers[] = clone $identifier; } } catch (Exception $e) { } } } return $identifiers; }
public function testBasicView() { $action = new CreateUserAction(); ok($action); $view = new ActionKit\View\StackView($action); ok($view); $html = $view->render(); ok($html); $resultDom = new DOMDocument(); $resultDom->loadXML($html); $finder = new DomXPath($resultDom); $nodes = $finder->query("//form"); is(1, $nodes->length); $nodes = $finder->query("//input"); is(4, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-widget')]"); is(8, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-widget-text')]"); is(2, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-label')]"); is(3, $nodes->length); $nodes = $finder->query("//input[@name='last_name']"); is(1, $nodes->length); $nodes = $finder->query("//input[@name='first_name']"); is(1, $nodes->length); }
public function testRouteExecutor() { $mux = new \Pux\Mux(); ok($mux); $mux->add('/hello/:name', array('HelloController2', 'helloAction'), array('require' => array('name' => '\\w+'))); $mux->add('/product/:id', array('ProductController', 'itemAction')); $mux->add('/product', array('ProductController', 'listAction')); $mux->add('/foo', array('ProductController', 'fooAction')); $mux->add('/bar', array('ProductController', 'barAction')); $mux->add('/', array('ProductController', 'indexAction')); ok($r = $mux->dispatch('/')); is('index', RouteExecutor::execute($r)); ok($r = $mux->dispatch('/foo')); is('foo', RouteExecutor::execute($r)); ok($r = $mux->dispatch('/bar')); is('bar', RouteExecutor::execute($r)); // XXX: seems like a gc bug here return; $cb = function () use($mux) { $r = $mux->dispatch('/product/23'); RouteExecutor::execute($r); }; for ($i = 0; $i < 100; $i++) { call_user_func($cb); } for ($i = 0; $i < 100; $i++) { ok($r = $mux->dispatch('/product/23')); is('product item 23', RouteExecutor::execute($r)); } ok($r = $mux->dispatch('/hello/john')); is('hello john', RouteExecutor::execute($r)); }
public function testRenderContentTextConvertsToUtf8() { $this->pagedTextResult->appendContentText("äöü"); $expected = htmlspecialchars("äöü", ENT_SUBSTITUTE, 'UTF-8'); assertThat($this->pagedTextResult->getText(), is(equalTo($expected))); $this->addToAssertionCount(1); }
public function testInitializeDirsAndFiles() { /** * dirs and files to create. */ $dirs = [__DIR__ . '/../../../sql', __DIR__ . '/../../../.dbup/applied', __DIR__ . '/../../../.dbup']; $files = [__DIR__ . '/../../../sql/V1__sample_select.sql', __DIR__ . '/../../../.dbup/properties.ini']; /** * cleaner the created files and dirs. */ $clean = function () use($dirs, $files) { foreach ($files as $file) { @unlink($file); } foreach ($dirs as $dir) { @rmdir($dir); } }; $clean(); $application = new Application(); $application->add(new InitCommand()); $command = $application->find('init'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName()]); foreach ($dirs as $dir) { assertThat(is_dir($dir), is(true)); } foreach ($files as $file) { assertThat(file_exists($file), is(true)); } $clean(); }
public function testVariableCache() { $cache = $this->_cms['cache']; $someVar = array('true' => true, 'some' => 'qwerty', 'arr' => array(1, 2, 3), 'obj' => (object) array('q' => 1, 'w' => 2, 'e' => 3)); $cache->set('some-var', $someVar, 'default', true); is($cache->get('some-var'), $someVar); }
/** * @test */ public function replace_PhraseWithTwoWordsAndAllWordsExistingInDictionary_ReturnsTranslation() { $dictionary = [$word = 'snow' => 'white watering', $wordB = 'sun' => 'hot lighting']; $this->replacer->setDictionary($dictionary); $result = $this->replacer->replace("It's \${$word}\$ outside and \${$wordB}\$"); assertThat($result, is(equalTo("It's white watering outside and hot lighting"))); }
public function testCode500() { $uniq = uniqid(); $result = $this->helper->request(__METHOD__, array('test-response-set500' => $uniq)); isContain($uniq, $result->body); is(500, $result->code); }
public function testRemoveCirclesDeg() { is('180 d', $this->val('540 d')->removeCircles()->dump(false)); is('-1 r', $this->val('-5 r')->removeCircles()->dump(false)); is('0 g', $this->val('1600 g')->removeCircles()->dump(false)); is('-0.55 t', $this->val('-5.55 t')->removeCircles()->dump(false)); }
public function testResult() { $result = new Result(); ok($result); $result->success('Success Tset'); is('success', $result->type); is(true, $result->isSuccess()); ok($result->message); ok($result->error('Error Tset')); is('error', $result->type); is(true, $result->isError()); ok($result->getMessage()); ok($result->valid('Valid Tset')); is('valid', $result->type); is(true, $result->isValidation()); ok($result->invalid('Valid Tset')); is('invalid', $result->type); is(true, $result->isValidation()); ok($result->completion('country', 'list', ['tw', 'jp', 'us'])); is('completion', $result->type); is(true, $result->isCompletion()); ok($result->desc('description')); ok($result->debug('debug')); ok($result->toArray()); ok($result->__toString()); }
public function testExplodeAssocWithCustomGlueArgumentsReturnsCorrectArrayValue() { $string = 'some_key:dummyvalue;another_key:anothervalue'; $expectedArray = ['some_key' => 'dummyvalue', 'another_key' => 'anothervalue']; $explodedValue = explode_assoc($string, ':', ';'); assertThat($explodedValue, is(equalTo($expectedArray))); }
public function testEvaluateFunction() { is(1, LazyRecord\Utils::evaluate(1)); is(2, LazyRecord\Utils::evaluate(function () { return 2; })); }
function testAddReferenceTexts() { $highlight1 = new Highlight(5, 8, 'type1', 2, 6, $this->license1->getId()); $highlights = array($highlight1); $this->highlight->addReferenceTexts($highlights); assertThat($highlight1->getInfoText(), is("10")); }
public function testexpand() { $paths = FileUtils::expand_path('/path/{to,to2,to3,foo,bar}/end'); is(count($paths), 5); $paths = FileUtils::expand_path('/path/foo/end'); is(count($paths), 1); }
function cmpr() { $s = array("", "123", "123q", "q123", "-456", "-456.7", "7.80", "9000000000", "9e10"); $i = array(0, 123, -456, 7.8, 90000000000); for ($ji = 0; $ji < 5; ++$ji) { cs($i[$ji]); } for ($js = 0; $js < 9; ++$js) { ci($s[$js]); } for ($ji = 0; $ji < 5; ++$ji) { for ($js = 0; $js < 9; ++$js) { is($i[$ji], $s[$js]); } } print "----------\n0 == 'q123'\n"; var_dump(0 == "q123"); print "----------\n123 == '123q'\n"; var_dump(123 == "123q"); print "----------\n123 == '123.0'\n"; var_dump(123 == "123.0"); print "----------\n90000000000 == '9e10'\n"; var_dump(9000000000 == "9e10"); print "----------\n0 == '-456'\n"; var_dump(0 == "-456"); }
public function testSetHostToCreateNewGallery() { $model = new RemoteModelStub(); $model->setHost('Flickr'); $gallery = $model->newModel(); assertThat($gallery, is(anInstanceOf('PullAutomaticallyGalleries\\RemoteApi\\RemoteApiModelInterface'))); }
/** * @test */ public function Converter2() { $converter = new MorzeConverter(); $res = $converter->recursiveParse('. .-.. .-.. --- .-- --- .-. .-.. -..'); // $res = $converter->recursiveParse('twig map asdfasdf'); assertThat($res, is('elloworld')); }
public function testAnnotations() { if (defined('HHVM_VERSION')) { echo "HHVM does not support Reflection to expand controller action methods"; return; } $controller = new ExpandableProductController(); ok($controller); ok(is_array($map = $controller->getActionMethods())); $routes = $controller->getActionRoutes(); is('', $routes[0][0], 'the path'); is('indexAction', $routes[0][1], 'the mapping method'); ok(is_array($routes)); $mux = new Pux\Mux(); // works fine // $submux = $controller->expand(); // $mux->mount('/product', $submux ); // gc scan bug $mux->mount('/product', $controller->expand()); ok($mux); $paths = array('/product/delete' => 'DELETE', '/product/update' => 'PUT', '/product/add' => 'POST', '/product/foo/bar' => null, '/product/item' => 'GET', '/product' => null); foreach ($paths as $path => $method) { if ($method) { $_SERVER['REQUEST_METHOD'] = $method; } else { $_SERVER['REQUEST_METHOD'] = 'GET'; } ok($mux->dispatch($path), $path); } }
public function testProductDetailsAreExtractedCorrectly() { $search_results_fixture = new stdClass(); $search_results_fixture->body = ' <div id="atfResults"> <ul> <li> <fig> <article class="acs-carousel-header"></article> </fig> </li> <li> <img class="s-access-image" src="/latte-cup.jpg" /> <a href="/latte-cup" class="s-access-detail-page"> <h2>Best latte cup</h2> </a> <span class="s-price">$12.05</span> </li> </ul> </div> '; $product_page_fixture = new stdClass(); $product_page_fixture->body = "\n <div id=\"productDescription\">\n <p>\n <div><img src=\"/some/image.jpg\" /></div>\n <p style=\"margin: 1em\">\t \n </p>\n <p>The best latte cup you will ever drink latte from. Period.</p>\n </p>\n </div>\n "; $Http = m::mock('Requests_Session'); // Mock HTTP request to product page $Http->shouldReceive('get')->with('/latte-cup')->once()->andReturn($product_page_fixture); // Mock HTTP request to search results $Http->shouldReceive('get')->once()->andReturn($search_results_fixture); $Amazon = new Amazon($Http); $Product = $Amazon->findOneProductByKeyword('latte cup'); assertThat($Product->title, is('Best latte cup')); assertThat($Product->price, is('$12.05')); assertThat($Product->image_uri, is('/latte-cup.jpg')); assertThat($Product->description, is('<p>The best latte cup you will ever drink latte from. Period. </p>')); }
/** * @test */ function matches_using_callback() { $matcher = new CallbackMatcher(function ($value) { return $value === "Hello, world."; }); assertThat($matcher->matches("Hello, world."), is(identicalTo(true))); }
public function testDiffByKeyWithNonDefaultKey() { $collectionStub = ModelStub::all(); $diff = $this->collection->diffByKey($collectionStub, 'name'); $diffNames = $diff->lists('name'); assertThat($diffNames, is(equalTo(['Taylor Otwell']))); }
public function testCreateRouterFromController() { $controller = new Fixtures\ProductController(); $router = $controller->getRouter(); assertThat($router->getStaticRoutes(), is(equalTo(['' => ['GET' => ['Rootr\\Fixtures\\ProductController', 'indexAction']]]))); assertThat($router->getVariableRoutes(), is(equalTo(['/(\\d+)' => ['GET' => [['Rootr\\Fixtures\\ProductController', 'showAction'], ['id']]], '/delete/([^/]+)' => ['DELETE' => [['Rootr\\Fixtures\\ProductController', 'deleteAction'], ['id']]]]))); }
public function testStringTemplate() { $t = new StringTemplate("{{foo}}"); ok($t); $output = $t->render(array('foo' => 1)); ok($output); is('1', $output); }
public function test() { $column = new Param('name'); $column->required(1); ok($column->required); $column->default('John'); is('John', $column->default); }
function test() { $element = new Element('div'); ok($element); is('<div/>', $element->render()); $element->addChild(new DOMText('Text')); is('<div>Text</div>', $element->render()); }
/** * Constructor * * @param var arg either a string or an io.Folder object */ public function __construct($arg) { if (is('io.Folder', $arg)) { $this->uri = $arg->getUri(); } else { $this->uri = rtrim(realpath($arg), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } }
/** * @test */ public function write_withContentsAndAFile_writesContentsToTheFileOnTheFileSystem() { $writtenContent = 'my new content that is awesome'; $file = Mockery::mock('FileSystem\\File[]', array('file.txt', $this->rootObject)); $file->content = $writtenContent; $this->fileSystem->write($file, VFS::url('root')); assertThat(file_get_contents(VFS::url('root/file.txt')), is(identicalTo($writtenContent))); }