Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin loaded twice in tests/bootstrap.php #1115

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="6@example.com"');
$this->assertResponseContains('id="email" value="6@example.com"');
$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
Loading