/**
  * Test a lookup to Google's public DNS and make sure that it returns appropriate information.
  */
 public function testGoogleLookup()
 {
     $request = new PageRequest('/phpwhois/lookup?q=8.8.8.8');
     // I need to spoof the GET request to add the necessary parameters.
     //$request->parameters['q'] = '8.8.8.8';
     $request->execute();
     $view = $request->getView();
     // The page should be a 200 status
     $this->assertEquals(200, $view->error);
     // Make sure this page is an ajax page.
     $this->assertEquals(View::MODE_AJAX, $view->mode);
     // And is a JSON page
     $this->assertEquals(View::CTYPE_JSON, $view->contenttype);
     // JSON Data needs to be set.
     $this->assertNotNull($view->jsondata);
     $this->assertNotEmpty($view->jsondata);
     // Make sure the JSON data is correct.
     $this->assertEquals('8.8.8.8', $view->jsondata['query']);
     $this->assertEquals('8.8.8.8', $view->jsondata['ip']);
     $this->assertEquals('8.8.8.0/24', $view->jsondata['network']);
     $this->assertEquals('Google Inc.', $view->jsondata['organization']);
     $this->assertEquals('US', $view->jsondata['country']);
     // @todo For whatever reason country_name isn't working... whatever, fix it soon.
     //$this->assertEquals('United States', $view->jsondata['country_name']);
 }
Example #2
0
	public function testBug(){
		$testcomponent = new Component_2_1(ROOT_PDIR . 'core/tests/testcomponent.xml');
		$this->assertInstanceOf('Component_2_1', $testcomponent);

		// Loading the component will read in the contents and get it setup.
		$testcomponent->load();
		$this->assertEquals('1.0.0', $testcomponent->getVersion());

		if($testcomponent->isInstalled()){
			// It's already installed?.... ok!
			$testcomponent->enable();
			$this->assertTrue($testcomponent->isEnabled());
		}
		else{
			// "Installing" a component should make it immediately enabled.
			$testcomponent->install();
			$this->assertTrue($testcomponent->isEnabled());
		}

		// So let's disable it!
		$testcomponent->disable();
		$this->assertFalse($testcomponent->isEnabled());

		// Now I can load it into core.
		// I couldn't do this before because the issue was that disabled components were being ignored completely.
		// This way when Core hits the component, it'll already be disabled.
		Core::Singleton()->_registerComponent($testcomponent);

		// And load up the page to make sure it's visible, (and enableable)
		// Update the current user so it has admin access.
		\Core\user()->set('admin', true);

		$request = new PageRequest('/updater');
		$request->execute();
		$view = $request->getView();
		$this->assertEquals(200, $view->error);
		// Obviously if the title gets changed, change it here to keep the bug from breaking!
		$this->assertEquals('t:STRING_SYSTEM_UPDATER', $view->title);

		// Get the body of this page and make sure that it's there.
		$html = $view->fetchBody();
		$matchtitle = 'Test Component';
		$matchmarkup = 'data-name="test-component" data-type="components"';


		$this->assertContains($matchtitle, $html, 'Failed to find the string "' . $matchtitle . '" on the updater page!');
		$this->assertContains($matchmarkup, $html, 'Failed to find the string "' . $matchmarkup . '" on the updater page!');


		// Lastly, cleanup this component!
		// Oh yeah.... uninstalling a component is needed!
		//$testcomponent->
		$this->markTestIncomplete('@todo Component uninstalling is not possible currently!');
	}
Example #3
0
 /**
  * Test that I can load the ATOM page and that it returns valid XML.
  * The XMLLoader will take care of the validation, since it should be a valid document anyway.
  */
 public function testATOMPage()
 {
     // Get the RSS feed and download it to a local file.
     $rewriteurl = $this->blog->get('rewriteurl');
     $this->assertNotEmpty($rewriteurl);
     // Go to the page and make sure that it loads up!
     $request = new PageRequest($rewriteurl . '.atom');
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error);
     $markup = $view->fetch();
     $this->assertNotEmpty($markup);
     // DEVELOPMENT DEBUG
     //echo $markup; // DEBUG //
     $xml = new XMLLoader();
     $xml->setRootName('feed');
     // If it's invalid markup, this load will throw an error, causing phpunit to return an error :)
     // If the bug is fixed, this will not throw any errors.
     $xml->loadFromString($markup);
     $parsedmarkup = $xml->asMinifiedXML();
     $this->assertNotEmpty($parsedmarkup);
 }
Example #4
0
 /**
  * Test the creation of a blog article based off the newly created blog
  *
  * @depends testCreateBlog
  */
 public function testCreateBlogArticle()
 {
     // Update the current user so it has admin access.
     \Core\user()->set('admin', true);
     // Setup some variables that will be used throughout this method.
     $title = 'New Test Blog Article';
     $randomsnippet = 'Random-Snippet-' . Core::RandomHex(10);
     $lorem = new BaconIpsumGenerator();
     $body = $lorem->getParagraph(1);
     // Tack on the random snipped I'll be looking for.
     $body .= $lorem->getParagraphsAsMarkup(8, $randomsnippet);
     $blog = new BlogModel(self::$TestBlogID);
     $request = new PageRequest('/blog/article/create/' . self::$TestBlogID);
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error, 'Checking that article creation returns a valid page');
     // The returned data should have a "form" available.  This is the actual creation form.
     /** @var $form Form */
     $form = $view->getVariable('form');
     $this->assertInstanceOf('Form', $form, 'Checking that the form is set from the blog article create controller');
     // Set some variables on the form
     $form->getElement('page[title]')->set('value', $title);
     $form->getElement('page[rewriteurl]')->set('value', $blog->get('rewriteurl') . '/' . \Core\str_to_url($title));
     $form->getElement('model[image]')->set('value', 'public/blog/blog-test-image.png');
     $form->getElement('model[body]')->set('value', $body);
     // Copy in the image
     $src = \Core\Filestore\Factory::File(ROOT_PDIR . 'components/blog/tests/blog-test-image.png');
     /** @var $dest \Core\Filestore\File */
     $dest = \Core\Filestore\Factory::File('public/blog/blog-test-image.png');
     $src->copyTo($dest, true);
     // make sure that it exists
     $this->assertTrue($dest->exists(), 'Checking that files can be copied into the public filestore');
     // And submit this form to the handler.
     // On a successful submission, it should be simply the URL of the blog.
     $formsubmission = call_user_func_array($form->get('callsmethod'), array($form));
     if ($formsubmission === false) {
         throw new Exception(implode("\n", $form->getErrors()));
     }
     // Go to the parent listing page and find this entry.
     $request = new PageRequest($blog->get('rewriteurl'));
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error);
     $html = $view->fetch();
     $this->assertContains($title, $html);
     $this->assertContains('itemtype="http://schema.org/BlogPosting"', $html);
     preg_match_all('#<div[^>]*itemtype="http://schema.org/BlogPosting"[^>]*>.*<a[^>]*href="(.*)"[^>]*>(.*)</a>#msU', $html, $matches);
     // Title should now have three keys, with at least one value each.
     $this->assertNotEmpty($matches[1]);
     $this->assertNotEmpty($matches[2]);
     // This node contains the URL.
     $foundurl = $matches[1][0];
     $foundtitle = trim($matches[2][0]);
     // Make sure the url contains the site url.
     $this->assertStringStartsWith(ROOT_URL, $foundurl);
     // And trim it off.  This is because PageRequest expects that the url is already trimmed.
     $foundurl = '/' . substr($foundurl, strlen(ROOT_URL));
     $this->assertEquals($title, $foundtitle);
     //$this->assertStringStartsWith('/blog/article/view/', $formsubmission, 'Checking that blog article creation was successful');
     // Go to the page and make sure that it loads up!
     $request = new PageRequest($foundurl);
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error, 'Checking that public blog article exists');
     $html = $view->fetch();
     $this->assertContains($title, $html, 'Checking that the public blog article page contains the correct title');
     $this->assertContains($randomsnippet, $html, 'Checking that the public blog article page contains the correct body');
     $this->assertContains('blog-test-image', $html, 'Checking that the public blog article page contains the correct image');
 }