public function testShouldPrintInformationAboutCommunication()
 {
     $request = new Request('irrelevant url');
     $response = new Response();
     $response->statusCode = 200;
     assertThat($this->getLog($request, $response), allOf(containsString($request->method), containsString($request->url), containsString((string) $response->statusCode)));
 }
Exemple #2
0
function setConfigItem($configPath, $key, $value)
{
    $key = sanitiseStringToAlphaNumeric($key);
    $value = sanitiseToIniValue($value);
    $currentValue = getConfigItem($configPath, $key);
    if (!is_writable($configPath)) {
        webServiceError('&error-config-file-not-writable;', 500, array('path' => $configPath));
    }
    $newConfigItemLine = $key . '="' . $value . '"';
    if ($currentValue === null) {
        $iniFilePointer = fopen($configPath, 'a');
        fwrite($iniFilePointer, "\n" . $newConfigItemLine . "\n");
        fclose($iniFilePointer);
        chmod($configPath, 0600);
        //security!
        return;
    }
    $iniLines = file($configPath);
    $newIniLines = array();
    $replaceExistingLine = False;
    foreach ($iniLines as $iniLine) {
        if (stringStartsWith($iniLine, $key) && ($currentValue == null || containsString($iniLine, $currentValue))) {
            $newIniLines[] = $newConfigItemLine . "\n";
        } elseif (trim($iniLine) != '') {
            $newIniLines[] = $iniLine;
        }
    }
    file_put_contents($configPath, implode('', $newIniLines));
    chmod($configPath, 0600);
    //security!
}
 public function testCreatePaymentAndGetItsStatus()
 {
     $this->givenCustomer();
     $this->whenCustomerCalls('createPayment', ['amount' => 1, 'currency' => Definition\Payment\Currency::CZECH_CROWNS, 'order_number' => 'order-test - ' . date('Y-m-d H:i:s'), 'order_description' => 'remote test', 'callback' => ['return_url' => 'http://www.your-url.tld/return', 'notification_url' => 'http://www.your-url.tld/notify']]);
     $this->apiShouldReturn('gw_url', containsString('.gopay.'));
     $idOfCreatedPayment = $this->response->json['id'];
     $this->whenCustomerCalls('getStatus', $idOfCreatedPayment);
     $this->apiShouldReturn('state', is(Definition\Response\PaymentStatus::CREATED));
 }
Exemple #4
0
 public function testSpecificPropertiesIni()
 {
     $application = new Application();
     $application->add(new StatusCommand());
     $command = $application->find('status');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), '--ini' => __DIR__ . '/../.dbup/properties.ini.test']);
     assertThat($commandTester->getDisplay(), is(containsString('| appending...        | V12__sample12_select.sql |')));
 }
Exemple #5
0
 public function testDryRunMode()
 {
     $application = \Phake::partialMock('Dbup\\Application');
     $application->add(new UpCommand());
     $command = $application->find('up');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), '--ini' => __DIR__ . '/../.dbup/properties.ini.test', '--dry-run' => true]);
     assertThat($commandTester->getDisplay(), is(containsString('now up is dry-run mode (--dry-run), so display only')));
     \Phake::verify($application, \Phake::times(0))->up(\Phake::anyParameters());
 }
 public function testReturnCorrectAttributeData()
 {
     $stub = Mockery::mock('PullAutomaticallyGalleries\\RemoteApi\\RemoteApiModelInterface')->shouldReceive('connect')->with('')->andReturn($this->userStub)->getMock();
     Test::double('RemoteUser', ['newModel' => $stub]);
     $user = RemoteUser::connect('DummyHost', '');
     assertThat($user->id, containsString('dummyhost_1'));
     assertThat($user->realname, is(equalTo($this->userStub['realname'])));
     assertThat($user->username, is(equalTo($this->userStub['username'])));
     assertThat($user->url, is(equalTo($this->userStub['url'])));
     assertThat($user->credentials, is(equalTo($this->userStub['credentials'])));
     assertThat($user->host, is(equalTo('DummyHost')));
 }
 /** @test */
 public function client_can_create_record()
 {
     $recordId = 'abc' . rand(1000, 9999999);
     $response = m::mock('Psr\\Http\\Message\\ResponseInterface');
     $response->shouldReceive('getBody')->once()->andReturn(json_encode(['id' => $recordId]));
     $guzzle = m::mock('\\GuzzleHttp\\Client');
     //Make sure the url contains the passed in data
     $guzzle->shouldReceive('post')->with(containsString('Test'), \Mockery::type('array'))->once()->andReturn($response);
     $sfClient = new \Crunch\Salesforce\Client($this->getClientConfigMock(), $guzzle);
     $sfClient->setAccessToken($this->getAccessTokenMock());
     $data = $sfClient->createRecord('Test', ['field1', 'field2']);
     $this->assertEquals($recordId, $data);
 }
Exemple #8
0
 public function testCreate()
 {
     $application = \Phake::partialMock('Dbup\\Application');
     $application->add(new CreateCommand());
     $command = $application->find('create');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'name' => 'foo', '--ini' => __DIR__ . '/../.dbup/properties.ini.test']);
     $display = $commandTester->getDisplay();
     assertThat($display, is(containsString('created')));
     preg_match('/\'(.+)\'/', $display, $matches);
     assertThat(1, count($matches));
     $migration = str_replace("'", "", $matches[0]);
     unlink(__DIR__ . '/../../../' . $migration);
 }
 public function testDescribesItself()
 {
     $each = everyItem(containsString('a'));
     $this->assertEquals('every item is a string containing "a"', (string) $each);
     $this->assertMismatchDescription('an item was "BbB"', $each, array('BbB'));
 }
Exemple #10
0
 public function testDoesNotMatchWhenContentDoesNotMatch()
 {
     assertThat('no match', self::$doc, not(hasXPath('user/name', containsString('Bobby'))));
     assertThat('no matches', self::$doc, not(hasXPath('user/role', equalTo('owner'))));
 }
 /**
  * Testing the hamcrest functions
  */
 public function testHamcrestTest()
 {
     $mock = ShortifyPunit::mock('SimpleClassForMocking');
     ShortifyPunit::when($mock)->first_method()->second_method(anything())->returns(1);
     ShortifyPunit::when($mock)->first_method(1)->second_method(equalTo(1))->returns(2);
     ShortifyPunit::when($mock)->first_method(2)->second_method(anything(), equalTo(1))->returns(3);
     ShortifyPunit::when($mock)->first_method(3)->second_method(containsString('foo bar'), anInstanceOf('SimpleClassForMocking'))->returns(4);
     ShortifyPunit::when($mock)->first_method(equalTo(4))->second_method(1)->returns(5);
     ShortifyPunit::when($mock)->first_method(equalTo(5))->second_method(not(1))->third_method(anyOf(1, 2, 3))->returns(6);
     ShortifyPunit::when($mock)->first_method(equalTo(5))->second_method(not(1))->third_method(anything())->returns(7);
     // HHVM Cannot serialize Exceptions
     //$exception = new \Exception('some message');
     $this->assertEquals($mock->first_method()->second_method(1), 1);
     $this->assertEquals($mock->first_method()->second_method(array()), 1);
     $this->assertNull($mock->first_method('foo'));
     //$this->assertNull($mock->first_method()->second_method('foo bar', $exception));
     $this->assertEquals($mock->first_method(1)->second_method(1), 2);
     $this->assertNull($mock->first_method(1)->second_method('bar'));
     $this->assertEquals($mock->first_method(2)->second_method('anything', 1), 3);
     $this->assertNull($mock->first_method(2)->second_method(false, 2));
     $this->assertEquals($mock->first_method(3)->second_method('foo bar', $mock), 4);
     $this->assertNull($mock->first_method(3)->second_method('foo', $mock));
     //$this->assertNull($mock->first_method(3)->second_method('foo bar', $exception));
     $this->assertEquals($mock->first_method(4)->second_method(1), 5);
     $this->assertEquals($mock->first_method(5)->second_method(2)->third_method(1), 6);
     $this->assertEquals($mock->first_method(5)->second_method(3)->third_method(2), 6);
     $this->assertEquals($mock->first_method(5)->second_method(2)->third_method(4), 7);
 }
Exemple #12
0
 function showGenerationStep()
 {
     $docvertDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
     $disallowDocumentGeneration = getGlobalConfigItem('doNotAllowDocumentGeneration');
     if ($disallowDocumentGeneration == 'true') {
         return $this->getThemeFragment('generation-disabled.htmlf');
     }
     if (isset($_REQUEST['step'])) {
         switch ($_REQUEST['step']) {
             case '4':
                 if (!isset($_REQUEST['pages'])) {
                     webServiceError('&error-webpage-generation-no-pages;');
                 }
                 $template = $this->getThemeFragment('generation-step4.htmlf');
                 $hiddenFormChosenPages = array();
                 $listItems = array();
                 foreach ($_REQUEST['pages'] as $page) {
                     $listItems[] = "\n\t\t\t\t" . '<li>' . $page . '</li>';
                     $hiddenFormChosenPages[] = "\n\t\t\t\t" . '<input type="hidden" name="pages[]" value="' . $page . '"/>';
                 }
                 $template = str_replace('{{page-order}}', implode($listItems), $template);
                 $template = str_replace('{{hidden-form-chosen-pages}}', implode($hiddenFormChosenPages), $template);
                 $generatorPipelines = glob($this->docvertRootDirectory . 'generator-pipeline' . DIRECTORY_SEPARATOR . '*');
                 $generatorPipelinesArray = array();
                 foreach ($generatorPipelines as $generatorPipeline) {
                     $generatorName = basename($generatorPipeline);
                     $generatorPipelinesArray[] = '<option value="' . $generatorName . '">' . $generatorName . '</option>';
                 }
                 return str_replace('{{generator-pipelines}}', implode('', $generatorPipelinesArray), $template);
             case '3':
                 $template = $this->getThemeFragment('generation-step3.htmlf');
                 $listItems = array();
                 foreach ($_REQUEST['pages'] as $page) {
                     $listItems[] = "\n\t\t\t\t" . '<option value="' . $page . '">' . $page . '</option>';
                 }
                 return str_replace('{{chosen-scrape-urls}}', implode($listItems), $template);
             case '2':
                 if (!isset($_REQUEST['url'])) {
                     webServiceError('&error-webpage-generation-url;');
                 }
                 $originalUrl = $_REQUEST['url'];
                 if (trim($originalUrl) == '') {
                     webServiceError('&error-webpage-generation-no-url-given;');
                 }
                 if (!stringStartsWith($originalUrl, 'http')) {
                     $originalUrl = 'http://' . $originalUrl;
                 }
                 $originalUrl = str_replace(array("\n", "\r", "\t", " "), '', $originalUrl);
                 include_once dirname(__FILE__) . '/http.php';
                 if (trim(getUrlLocalPart($originalUrl)) == '') {
                     $originalUrl = followUrlRedirects($originalUrl . '/');
                 } else {
                     $originalUrl = followUrlRedirects($originalUrl);
                 }
                 if ($originalUrl === false) {
                     webServiceError('&error-webpage-cannot-get-url;', 500, array('url' => $originalUrl));
                 }
                 $page = file_get_contents($originalUrl);
                 $baseTagPattern = "/<base[^>]*?href=([^>]*?)>/is";
                 preg_match($baseTagPattern, $page, $matches);
                 if (count($matches) > 0) {
                     $originalUrl = trim($matches[1]);
                     $originalUrl = substr($originalUrl, 1, strlen($originalUrl) - 2);
                 }
                 $url = $originalUrl;
                 $connectionPart = getUrlConnectionPart($url);
                 $getUrlLocalPart = getUrlLocalPart($url);
                 $localPartDirectory = getUrlLocalPartDirectory($url);
                 $links = array();
                 $matches = null;
                 preg_match_all('/href="(.*?)"/', $page, $matches);
                 $matches = $matches[1];
                 $urls = array();
                 $urls[$originalUrl] = 'value that does not matter';
                 foreach ($matches as $match) {
                     $link = $match;
                     if (stringStartsWith($link, '/')) {
                         $link = $connectionPart . $link;
                     } elseif (stringStartsWith($link, "http://") || stringStartsWith($link, "https://")) {
                     } elseif (stringStartsWith($link, "mailto:")) {
                     } else {
                         $link = $connectionPart . resolveRelativeUrl($localPartDirectory . $link);
                     }
                     if (containsString($link, '#')) {
                         $link = substringBefore($link, '#');
                     }
                     if (stringEndsWith($link, '?')) {
                         $link = substringBefore($link, '?');
                     }
                     if (stringStartsWith($link, 'http')) {
                         $fileExtension = substr($link, strrpos($link, '.') + 1);
                         switch ($fileExtension) {
                             case 'avi':
                             case 'mov':
                             case 'mpg':
                             case 'css':
                             case 'jpeg':
                             case 'jpg':
                             case 'gif':
                             case 'png':
                             case 'bmp':
                             case 'apng':
                             case 'tiff':
                             case 'ico':
                             case 'js':
                             case 'gz':
                             case 'tar':
                             case 'zip':
                             case 'bin':
                             case 'sit':
                             case 'mp3':
                             case 'mp4':
                             case 'wav':
                             case 'swf':
                             case 'fla':
                             case 'rss':
                             case 'atom':
                             case 'pdf':
                             case 'xls':
                             case 'doc':
                             case 'txt':
                             case 'pps':
                                 break;
                             default:
                                 $urls[$link] = 'value that does not matter';
                         }
                     }
                 }
                 $urls = array_keys($urls);
                 $mostLikelyUrls = array();
                 $possibleUrls = array();
                 $unlikelyUrls = array();
                 $numberOfSlashesInOriginalUrl = strlen($originalUrl) - strlen(str_replace('/', '', $originalUrl));
                 foreach ($urls as $url) {
                     $url = followUrlRedirects($url);
                     if (trim($url) != '') {
                         $numberOfSlashesInUrl = strlen($url) - strlen(str_replace('/', '', $url));
                         if (stringStartsWith($url, $connectionPart . $localPartDirectory) && $numberOfSlashesInUrl == $numberOfSlashesInOriginalUrl) {
                             $mostLikelyUrls[] = $url;
                         } elseif (stringStartsWith($url, $connectionPart)) {
                             $possibleUrls[] = $url;
                         } else {
                             $unlikelyUrls[] = $url;
                         }
                     }
                 }
                 asort($unlikelyUrls);
                 $itemId = 0;
                 foreach ($mostLikelyUrls as $url) {
                     $links[] = '<li class="orderingItem"><label for="urlId' . $itemId . '"><input type="checkbox" name="pages[]" value="' . $url . '" id="urlId' . $itemId . '" checked="checked"/><span class="title">' . $url . '</label></span></li>' . "\n";
                     $itemId++;
                 }
                 foreach ($possibleUrls as $url) {
                     $links[] = '<li class="orderingItem"><label for="urlId' . $itemId . '"><input type="checkbox" name="pages[]" value="' . $url . '" id="urlId' . $itemId . '"/><span class="title">' . $url . '</label></span></li>' . "\n";
                     $itemId++;
                 }
                 foreach ($unlikelyUrls as $url) {
                     $links[] = '<li class="orderingItem"><label for="urlId' . $itemId . '"><input type="checkbox" name="pages[]" value="' . $url . '" id="urlId' . $itemId . '"/><span class="title">' . $url . '</label></span></li>' . "\n";
                     $itemId++;
                 }
                 $step2Template = $this->getThemeFragment('generation-step2.htmlf');
                 $step2Template = str_replace('{{scrape-results}}', implode('', $links), $step2Template);
                 $step2Template = str_replace('{{scrape-url}}', $url, $step2Template);
                 return $step2Template;
             default:
                 return $this->getThemeFragment('generation-step1.htmlf');
         }
     } else {
         return $this->getThemeFragment('generation-step1.htmlf');
     }
 }
Exemple #13
0
function getUrlLocalPartDirectory($url)
{
    $url = getUrlLocalPart($url);
    if (containsString($url, '?')) {
        $url = substringBefore($url, '?');
    }
    return substr($url, 0, strrpos($url, '/') + 1);
}
 function testWeirdChars()
 {
     $weirdCharclearedGetter = new WeirdCharclearedGetter();
     $json = $weirdCharclearedGetter->cJson(0);
     assertThat($json, containsString('"good":"\\u6f22"'));
     assertThat($json, containsString('"esc":"escape"'));
     assertThat($json, containsString('"uml":" \\u00fc "'));
 }