Skip to content

Commit

Permalink
Merge pull request #1115 from ajibarra/14.next-cake5
Browse files Browse the repository at this point in the history
Fix plugin loaded twice in tests/bootstrap.php
  • Loading branch information
ajibarra authored Jan 17, 2025
2 parents 6954c72 + a464935 commit 982a5c7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
12 changes: 7 additions & 5 deletions src/Model/Behavior/SocialAccountBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class SocialAccountBehavior extends Behavior
public function initialize(array $config): void
{
parent::initialize($config);
$this->_table
->belongsTo('Users')
->setForeignKey('user_id')
->setJoinType('INNER')
->setClassName(Configure::read('Users.table'));
if (!$this->_table->hasAssociation('Users')) {
$this->_table
->belongsTo('Users')
->setForeignKey('user_id')
->setJoinType('INNER')
->setClassName(Configure::read('Users.table'));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public function testLoginGetRequestNoSocialLogin()
$this->assertResponseNotContains('Username or password is incorrect');
$this->assertResponseContains('<form method="post" accept-charset="utf-8" action="/login">');
$this->assertResponseContains('<legend>Please enter your username and password</legend>');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true"');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password"');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me"');
$this->assertResponseContains('<button type="submit">Login</button>');
$this->assertResponseContains('<a href="/register">Register</a>');
Expand All @@ -114,8 +114,8 @@ public function testLoginGetRequest()
$this->assertResponseNotContains('Username or password is incorrect');
$this->assertResponseContains('<form method="post" accept-charset="utf-8" action="/login">');
$this->assertResponseContains('<legend>Please enter your username and password</legend>');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true"');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password"');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me"');
$this->assertResponseContains('<button type="submit">Login</button>');
$this->assertResponseContains('<a href="/register">Register</a>');
Expand Down Expand Up @@ -143,8 +143,8 @@ public function testLoginPostRequestInvalidPassword()
$this->assertResponseContains('Username or password is incorrect');
$this->assertResponseContains('<form method="post" accept-charset="utf-8" action="/login">');
$this->assertResponseContains('<legend>Please enter your username and password</legend>');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" aria-required="true" value="user-2"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" aria-required="true" value="123456789"');
$this->assertResponseContains('<input type="text" name="username" required="required" id="username" value="user-2"');
$this->assertResponseContains('<input type="password" name="password" required="required" id="password" value="123456789"');
$this->assertResponseContains('<input type="checkbox" name="remember_me" value="1" checked="checked" id="remember-me"');
$this->assertResponseContains('<button type="submit">Login</button>');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testRegister()
$this->assertResponseContains('<input type="text" name="first_name" id="first-name" maxlength="50"');
$this->assertResponseContains('<input type="text" name="last_name" id="last-name" maxlength="50"');
$this->assertResponseContains('<input type="hidden" name="tos" value="0"');
$this->assertResponseContains('<label for="tos"><input type="checkbox" name="tos" value="1" required="required" id="tos" aria-required="true">Accept TOS conditions?</label>');
$this->assertResponseContains('<label for="tos"><input type="checkbox" name="tos" value="1" required="required" id="tos">Accept TOS conditions?</label>');
$this->assertResponseContains('<button id="btn-submit" type="submit">Submit</button>');
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public function testRegisterPostWithErrors()
$this->assertResponseContains('<input type="text" name="first_name" id="first-name" value="" maxlength="50"');
$this->assertResponseContains('<input type="text" name="last_name" id="last-name" value="" maxlength="50"');
$this->assertResponseContains('<input type="hidden" name="tos" value="0"');
$this->assertResponseContains('<label for="tos"><input type="checkbox" name="tos" value="1" required="required" id="tos" aria-required="true">Accept TOS conditions?</label>');
$this->assertResponseContains('<label for="tos"><input type="checkbox" name="tos" value="1" required="required" id="tos">Accept TOS conditions?</label>');
$this->assertResponseContains('<button id="btn-submit" type="submit">Submit</button>');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testCrud()
$this->assertResponseContains('<a href="/users/view/00000000-0000-0000-0000-000000000001">View</a>');
$this->assertResponseContains('<a href="/users/change-password/00000000-0000-0000-0000-000000000001">Change password</a>');
$this->assertResponseContains('<a href="/users/edit/00000000-0000-0000-0000-000000000001">Edit</a>');
$this->assertResponseContains('style="display:none;" method="post" action="/users/delete/00000000-0000-0000-0000-000000000001"');
$this->assertResponseContains('method="post" style="display:none;" action="/users/delete/00000000-0000-0000-0000-000000000001"');
$this->assertResponseContains('>Delete<');

$this->assertResponseContains('<td>user-6</td>');
Expand All @@ -69,7 +69,7 @@ public function testCrud()
$this->assertResponseContains('<a href="/users/view/00000000-0000-0000-0000-000000000006">View</a>');
$this->assertResponseContains('<a href="/users/change-password/00000000-0000-0000-0000-000000000006">Change password</a>');
$this->assertResponseContains('<a href="/users/edit/00000000-0000-0000-0000-000000000006">Edit</a>');
$this->assertResponseContains('style="display:none;" method="post" action="/users/delete/00000000-0000-0000-0000-000000000006"');
$this->assertResponseContains('method="post" style="display:none;" action="/users/delete/00000000-0000-0000-0000-000000000006"');

$this->get('/users/change-password/00000000-0000-0000-0000-000000000006');
$this->assertFlashMessage('Changing another user\'s password is not allowed');
Expand All @@ -95,13 +95,13 @@ public function testCrud()

$this->get('/users/edit/00000000-0000-0000-0000-000000000006');
$this->assertResponseContains('<input type="text" name="username" required="required');
$this->assertResponseContains('id="username" aria-required="true" value="user-6"');
$this->assertResponseContains('id="username" value="user-6"');
$this->assertResponseContains('<input type="email" name="email" required="required');
$this->assertResponseContains('id="email" aria-required="true" value="[email protected]"');
$this->assertResponseContains('id="email" value="[email protected]"');
$this->assertResponseContains('<input type="text" name="first_name" id="first-name" value="first-user-6');
$this->assertResponseContains('<input type="text" name="last_name" id="last-name" value="firts name 6');
$this->assertResponseContains('<label for="active"><input type="checkbox" name="active" value="1" id="active" checked="checked">Active</label>');
$this->assertResponseContains('style="display:none;" method="post" action="/users/delete/00000000-0000-0000-0000-000000000006"');
$this->assertResponseContains('method="post" style="display:none;" action="/users/delete/00000000-0000-0000-0000-000000000006"');
$this->assertResponseContains('<a href="/users/index">List Users</a>');

$this->enableSecurityToken();
Expand All @@ -124,7 +124,7 @@ public function testCrud()
$this->assertResponseContains('<a href="/users/edit/00000000-0000-0000-0000-000000000006">Edit User</a>');
$this->assertResponseContains('<a href="/users/add">New User</a>');
$this->assertResponseContains('<a href="/users/index">List Users</a>');
$this->assertResponseContains('style="display:none;" method="post" action="/users/delete/00000000-0000-0000-0000-000000000006"');
$this->assertResponseContains('method="post" style="display:none;" action="/users/delete/00000000-0000-0000-0000-000000000006"');

$this->post('/users/delete/00000000-0000-0000-0000-000000000006');
$this->assertRedirect('/users/index');
Expand Down
5 changes: 2 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@
Cake\Core\Configure::write('Session', [
'defaults' => 'php',
]);
session_id('cli');

Plugin::getCollection()->add(new \CakeDC\Users\Plugin([
'path' => dirname(dirname(__FILE__)) . DS,
'routes' => true,
]));

if (file_exists($root . '/config/bootstrap.php')) {
require $root . '/config/bootstrap.php';
}
Expand Down Expand Up @@ -136,9 +138,6 @@ class_alias('TestApp\Controller\AppController', 'App\Controller\AppController');
]);
\Cake\Utility\Security::setSalt('yoyz186elmi66ab9pz4imbb3tgy9vnsgsfgwe2r8tyxbbfdygu9e09tlxyg8p7dq');

Plugin::getCollection()->add(new \CakeDC\Users\Plugin());
session_id('cli');

\Cake\Core\Configure::write('Users.AllowedRedirectHosts', [
'localhost',
'example.com',
Expand Down

0 comments on commit 982a5c7

Please sign in to comment.