assertTitle fails on Selenium + PHPUnit - selenium

I am trying a very simple test like this :
public function index()
{
$this->open('');
$this->assertTitle(Yii::app()->name);
}
with the appropriate fixtures :
'accueil' => array(
'id' => 1,
'title' => Yii::app()->name,
'name' => "accueil",
[etc...]
),
But when I run the functional test, the assertTitle method fails :
Failed command: assertTitle('comptabilite-personnelle.net (dev)')
Failed asserting that 'comptabilite-personnelle.net (dev)' matches
PCRE pattern "/^comptabilite-personnelle.net (dev)$/".
OTOH, the following code does not fail :
Fixtures :
'accueil' => array(
'id' => 1,
'title' => 'whatever',
'name' => "accueil",
[etc...]
),
Assertion :
$this->assertTitle('whatever');
Any idea about this behavior welcome !

If you just want to check if your page title contains you app name and not want to check if your page title is exactly the same as your app name you need to do it like that:
$this->assertTitle('regexp:.*' . Yii::app()->name . '.*');

Related

Mollie applicationfee's

for a customer I need to charge an applicationFee for each order that has been processed on their site from the sub customers. The whole code is working with authentication and everything.
But from the moment I'm adding:
'applicationFee' => $applicationFee
to the call I receive this error:
Error executing API call (422: Unprocessable Entity): Unable to process application request for this account. Documentation: https://docs.mollie.com/guides/handling-errors"
The content of "$applicationFee" is correct, that I was able to check already.
The $shop_mollie_data->profile_id containts the different websiteprofileId's found on the Mollie dashboard.
$provider = new MollieConnectProvider($request, $clientId, $clientSecret, $redirectUrl);
$newAccessToken = $provider->getRefreshTokenResponse($shop_mollie_data->refresh_token);
$mollie = new MollieApiClient();
$mollie->setAccessToken($newAccessToken['access_token']);
$payment = $mollie->payments->create([
'amount' => [
'currency' => 'EUR',
'value' => (string) (sprintf("%.2f", $order_total))
],
'description' => ucfirst($shop->name) . ' - Order #' . $order_nm,
'webhookUrl' => $url_callback,
'redirectUrl' => $url_success,
'method' => 'bancontact',
'locale' => $language_id,
'metadata' => [
"order_id" => $ref,
"shop id" => $shop->id
],
'profileId' => $shop_mollie_data->profile_id,
'testmode' => true,
'applicationFee' => $applicationFee
]);

git ignore Yii database details

Some of the details in the main.php needed by all application instances (URL details) and some details will be specific to each application instance (database details).
Is there any idea to separate the database details from protected/config/main.php?
Just include the shared configuration from another PHP file:
main.php:
return array
(
....
'components' => array
(
'db' => include('sharedDatabaseConfiguration.php');
)
);
sharedDatabaseConfiguration.php:
return array('host' => ...);
You might have to add a path or something, depending where the file is stored.
Edit: Btw, Yii also has a fancy CMap::mergeArray() function that can do something similar (in case you want to "augment" the contents of a single config file with that from another one. Look at the default generated console.php for an example of that.
You can find an idea here: Manage application configuration in different modes .
Basically it works by importing a different PHP file (your db configuration) and merging the includedarrays:
<?php
return CMap::mergeArray(
require(dirname(__FILE__).'/db-config.php'),
array(
'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name' => 'Page Title',
...
)
);
?>
You can use separate configuration file (e.g. protected/config/production.php), that is based on your main configuration file and that overrides some settings using CMap::mergeArray as this answer suggests:
return CMap::mergeArray(
require(dirname(__FILE__) . '/main.php'),
array(
'components' => array(
'db' => array(
'connectionString' => '...',
'username' => '...',
'password' => '...',
),
),
)
);
Then you can add protected/config/production.php to .gitignore.

CakePHP Auth->login not generating query for request data

I have the Auth component working perfectly for an application running Cake 2.4.1, and I need to copy it to another application that is also running Cake 2.4.1. I copied over everything I could think of that has to do with Auth stuff, but it just does not work in the second application. It refuses to log me in. The call to $this->Auth->login() fails even though it gets exactly the same data as the application that works.
Both applications are using exactly the same database and user login.
Both applications get exactly the same request data in the POST request.
First of all, here is my setup.
In AppController.php:
public $uses = array ('User');
public $components = array ( 'Session',
'CPRACL.CPRACL' => array (),
'Auth' => array (
// 'loginAction' => array ('controller' => 'users', 'action' => 'login'),
// 'logoutRedirect' => '/users/login',
// 'loginRedirect' => '/',
'authenticate' => array (
'Form' => array (
'fields' => array ('username' => 'email_address'),
'scope' => array ('User.active' => 1)
)
),
'authorize' => array ('Controller'),
// 'unauthorizedRedirect' => '/' // when going to a page the user is not authorized to go to
)
);
The commented out lines use the defaults, but they are included for reference to their default values. This is exactly the same in both applications. CPRACL is a plugin component that I am using instead of Cake's ACL component, but it fails long before it gets to any of that.
Also in AppController.php:
public function beforeFilter ()
{
$login_user = $this->User->find ('first', array ('conditions' => array ('id' => $this->Auth->user ('id'))));
if (!empty ($login_user))
$this->set ('login_user', $login_user ['User']);
}
public function isAuthorized ($user = null)
{
// This never gets called in the application that does not work, but it does get called in the one that works.
}
In both applications, it sets up the Auth component as defined in AppController.php, then it calls beforeFilter to check to see if the user is already logged in. This is a convenience so that when they get redirected to a different page, the application can display the username of the user who is logged in. It works fine and I don't think it is causing any problems.
The next thing that happens is it calls UsersController::login()
public function login ()
{
$redirect_url = $this->Auth->redirectUrl ();
if ($this->Auth->loggedIn ())
return $this->redirect ($redirect_url);
//die (print_r ($this->request->data, true));
if ($this->request->is ('post'))
{
//die (Debugger::dump ($this->Auth));
if ($this->Auth->login ())
return $this->redirect ($redirect_url);
else
return $this->redirect ($this->Auth->loginAction);
}
}
I used the two commented out lines to compare what is happening between the two applications. The two applications get exactly the same data in the post. For the dump of the Auth object, here is what I get:
object(AuthComponent) {
components => array(
(int) 0 => 'Session',
(int) 1 => 'RequestHandler'
)
authenticate => array(
'Form' => array(
[maximum depth reached]
)
)
authorize => array(
(int) 0 => 'Controller'
)
ajaxLogin => null
flash => array(
'element' => 'default',
'key' => 'auth',
'params' => array([maximum depth reached])
)
loginAction => array(
'controller' => 'users',
'action' => 'login',
'plugin' => null
)
loginRedirect => null
logoutRedirect => array(
'controller' => 'users',
'action' => 'login',
'plugin' => null
)
authError => 'You are not authorized to access that location.'
unauthorizedRedirect => true
allowedActions => array(
(int) 0 => 'register',
(int) 1 => 'login',
(int) 2 => 'logout'
)
request => object(CakeRequest) {}
response => object(CakeResponse) {}
settings => array(
'authenticate' => array(
[maximum depth reached]
),
'authorize' => array(
[maximum depth reached]
)
)
Session => object(SessionComponent) {}
[protected] _authenticateObjects => array()
[protected] _authorizeObjects => array()
[protected] _user => array()
[protected] _methods => array(
(int) 0 => 'index',
(int) 1 => 'view',
(int) 2 => 'add',
(int) 3 => 'register',
(int) 4 => 'login',
(int) 5 => 'logout',
(int) 6 => 'toggleactive',
(int) 7 => 'changePassword',
(int) 8 => 'passwordHash',
(int) 10 => 'edit_pwd',
(int) 11 => 'edit_your_pwd',
(int) 12 => 'isAuthorized'
)
[protected] _Collection => object(ComponentCollection) {}
[protected] _componentMap => array(
'Session' => array(
[maximum depth reached]
),
'RequestHandler' => array(
[maximum depth reached]
)
)
}
That is what both applications return from the Auth object dump when I send the login request. It says the user is not authorized to access that location, but I think that is because it hasn't actually logged the user in yet, so I don't think the dump of that Auth object is of much value, but I included it here anyway.
But here is the most important part because it is the only thing that is obviously different between the two applications. When I perform the login on the working application, it logs me in successfully and my layout (which displays the most recent query) shows this query. Notice the id field. The id field is correct in the query and it works.
SELECT `User`.`id`, `User`.`user_id`, `User`.`email_address`, `User`.`first_name`, `User`.`last_name`, `User`.`password`, `User`.`active`, `User`.`created`, `User`.`modified` FROM `brian_cake_test`.`users` AS `User` WHERE `id` = '529f9a8c-3460-46a2-a97c-6a6242a26b88' LIMIT 1
But when I do exactly the same thing for the application that does not work, everything happens exactly the same way except that it redirects me back to the login page, which it should do if it fails to login, and it displays this query in my layout.
SELECT `User`.`id`, `User`.`user_id`, `User`.`email_address`, `User`.`first_name`, `User`.`last_name`, `User`.`password`, `User`.`active`, `User`.`created`, `User`.`modified` FROM `brian_cake_test`.`users` AS `User` WHERE `id` IS NULL LIMIT 1
Notice how the id is NULL in the second query. I have no idea why this is happening.
My User.php model is just an empty class, exactly the same in both application, but one works perfectly and the other does not.
<?php
App::uses ('AppModel', 'Model');
class User extends AppModel
{
public $name = 'User';
}
I have racked my brain trying to figure out what is different between these two applications, and I can't think of anything, and nothing I try will make it work. I don't want to post hundreds of lines of code when I know that 99% of it has nothing to do with this problem, but I have no idea why it works in one but not the other. I will gladly post more information if you think you might know what the problem is. Any help would be much appreciated. This is very important to me.
Actually if its exactly the same code and DB it shouldn't be a reason not to work.
Have you tried clearing the cache folders? Those files sometimes mess up the app.

YouTube API Upload Video as 'Unlisted' or 'Private'?

I am using a Wordpress plugin called 'YouTube Uploader', it allows you to upload YouTube videos from your WordPress site, it is working for me but the only issue is that it uploads the videos as Public and I need them to go up as Unlisted or Private (either will do). If someone could tell me what to add/change to make it do this, it would be greatly appreciated, thanks!
I uploaded the code to Pastebin as I didn't want to fill this entire post with code, heres the link: http://pastebin.com/GfQjhiiq
Thanks!
I'm not that clued up on Wordpress but what you're looking for is a tag called <yt:private/>
<yt:private/> is a child of media:group so a sample xml schema could look something like the following. (Note where <yt:private/> sits within the code block):
<media:group>
<media:title type="plain">Title here</media:title>
<media:description type="plain">Description here</media:description>
<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Travel</media:category>
<media:keywords>keyword1</media:keywords>
<yt:private/>
</media:group>
Hope this is of some use.
I think this method is pretty outdated. But there is a work around if you were to use the the Plain PHP API method...
This Part does the trick:
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
In the bigger scheme:
$this->Zend->loadClass('Zend_Gdata_ClientLogin');
$this->Zend->loadClass('Zend_Gdata_YouTube');
$client = Zend_Gdata_ClientLogin::getHttpClient(ZEND_GDATA_CLIENT_EMAIL, ZEND_GDATA_CLIENT_PASS, 'youtube');
$client->setHeaders('X-GData-Key', "key=".ZEND_GDATA_YOUTUBE_DEVELOPER_KEY);
$yt = new Zend_Gdata_YouTube($client);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element(
'yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', ''
);
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Sports');
The whole Gist is over here: https://gist.github.com/1044349

Magento api giving problem if image not exist

I am using magento api ..
in which i have used "catalog_product_attribute_media.create" ..thats giving problem if it doesn't get image on server where this image exist.
problem is that ..it stoping my script to run further
I have checked if URL is none.. but how can i handle this situation that is it getting url ...but image not exist
here is my code...
if($products[$counter]->small_image_url){//check if url exists
$newImage = array(
'file' => array(
'name' => 'file_name',
'content' => base64_encode(file_get_contents($products[$counter]->small_image_url)),
'mime' => 'image/jpeg'),
'label' => $products[$counter]->product_name,
'position' => 2,
'types' => array('thumbnail_image'),
'exclude' => 0
);
$imageFilename = $proxy->call($sessionId, 'product_media.create', array($sku, $newImage));
}
Have you tried checking for an empty string?
if($products[$counter]->small_image_url && $products[$counter]->small_image_url != '')