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

Toolbar Pattern + Test #19

Open
shakty opened this issue Sep 22, 2011 · 20 comments
Open

Toolbar Pattern + Test #19

shakty opened this issue Sep 22, 2011 · 20 comments

Comments

@shakty
Copy link
Owner

shakty commented Sep 22, 2011

No description provided.

@ghost ghost assigned shakty Sep 22, 2011
@ghost ghost assigned ruioaix Oct 19, 2011
@shakty
Copy link
Owner Author

shakty commented Oct 20, 2011

The Toolbar module manages the black bar on top of the site which contains link to the important sections of the website (e.g. People, Configuration, Patterns, etc.). It also manages another bar for shortcuts that users can add.

Now the top links are automatically added depending on the path which is given inside each module. The shortcuts can be set through the form reachable if you click on the top right link 'Edit shortcuts'. For me that is available at the url:

http://localhost/drupal-7.8/admin/config/user-interface/shortcut/shortcut-set-1

Write a pattern that set the permission for the toolbar, e.g. who can see it (which roles?) and enable the shortcuts.
Write a Simple Test that checks that.

@ruioaix
Copy link
Contributor

ruioaix commented Oct 28, 2011

I have thought about this test for some time, but I haven't got the point of "set the permission for the toolbar".
Opinion1: should I add a new permission to the toolbar? I look the "toolbar.module" code, there is a permission named "access toolbar".
"set the permission for the toolbar" means that I need to write a toolbar.yaml to change the "access toolbar" permission to some other permission, such as "Administer content".
is this opinion right?

Opinion2: I look at the page "localhost/~ray/drupal78/admin/people/permissions" (on my PC), the permission "access toolbar" named "Use the administration toolbar" is on the list.
on the right of the permission list, there are three boxes correspond to three kinds of users on my PC, should I write a toolbar.yaml to select the boxes for the permission "access toolbar"?
is this opinion right?

the last question: besides of the yaml file, do I need to write the toolbar.inc file like "Patterns/components/block.inc"?

@shakty
Copy link
Owner Author

shakty commented Oct 28, 2011

Hi,

I didn't mention explicitly on my previous post, but

  1. you need to write a patterns.toolbar.inc file
  2. you have to write a yaml file which sets which shortcuts are in the toolbar
  3. you have to write a yaml file which sets the permission for the toolbar (both option 1 and 2).

As for point 3. I believe that @csko may have already written the component for setting the permissions, but I am not sure whether it was ported to the new version of pattern. Please ask him, in the chat or by mailing list.

@ruioaix
Copy link
Contributor

ruioaix commented Oct 28, 2011

thanks, ste.
If I get any questions, I will comment again.

@ruioaix
Copy link
Contributor

ruioaix commented Nov 4, 2011

Hi
I have pushed components/patterns.toolbar.inc and patterns/toolbar.yaml to the repo.
in the pattern toolbar.yaml, we can add the toolbar's permission to some roles and delete the toolbar's permission from some roles.
if a role have the toolbar permission, the users with the roles can see the toolbar.

I looked the shortcut module's code, I think a independent components/patterns.shortcut.inc should be better, now the pattern.shortcut.inc can do two things: add shortcut set and rename a shortcut set( there are two shortcut**.yaml in pattern dir), this two works fine.

I will add the other test to shortcut later.

@csko
Copy link
Contributor

csko commented Nov 4, 2011

Hi, I've commented on your commit 9ec4582. You can see my comments between the lines of your code.

@csko
Copy link
Contributor

csko commented Nov 4, 2011

@shakty, @xrfind
3. you have to write a yaml file which sets the permission for the toolbar (both option 1 and 2).

I'm not sure how to integrate this into an other component, but I'm pretty sure replicating it (as in patterns.toolbar.inc right now) is not right.

@ruioaix
Copy link
Contributor

ruioaix commented Nov 12, 2011

@shakty,@csko
jobs done.

@shakty
Copy link
Owner Author

shakty commented Nov 16, 2011

thanks for the job! Some remarks:

1- I don't find the test. That should be under the patterns/tests/ directory.
2- Please adjust the names you use on the yaml to something shorter, and easier to understand (for western people :))
2.b - Please make them consistent: e.g. the same shorcut_set_name should be used across different patterns (so that I don't have to change it manually to run the pattern)
3- I seems not to be running correctly. If run add new shortcut set (create) and then add a link to a shortcut set (create), it says that the pattern run correctly, but in fact nothing happens.
4- You are still using custom functions to set the roles which can see the toolbar. I don't know if can do this through a form, that would be better, but maybe the pattern component for that is not ready (@csko should say something).

Thanks a lot, I see you did a lot of work!

@csko
Copy link
Contributor

csko commented Nov 16, 2011

3 - Isn't that beacuse the roles are commented out in the yaml file? Why is that?
4 - No, that's still not ready. I'll try to implement it one of these days...

@ruioaix
Copy link
Contributor

ruioaix commented Nov 17, 2011

for @shakty 1:
I'm sorry, I thought the "Patterns/patterns/xxx.yaml" is the test, how to write test?

for @shakty 2&2.b:
Done, you can run the "add new shortcut_set(create)" to add a "new_set_fortest" shorcut_set.
see:http://localhost/~ray/drupal79/user#overlay=admin/config/user-interface/shortcut (for me)
Then, run the "switch shortcut set for users(modify)" to change admin(the user login rightnow,for me is admin)'s shortcut_set to "new_set_fortest" set.
see:http://localhost/~ray/drupal79/user#overlay=user/1/shortcuts (for me)
Then, run the "add a link to a shortcut set(modify)" to add a link"link_admcont" to "new_set_fortest" set.
the "link_admcont" should be in the shortcut bar now.

for @shakty 3:
Is that because the shortcut_set_name variable in "add a link to a shortcut set(create)" is not the shortcut_set you are using on that moment?

for @shakty 4:
I am sorry, I forget delete the comment in the pattern.toolbar.inc, It works through the form right now.

@ruioaix
Copy link
Contributor

ruioaix commented Nov 17, 2011

for @csko 3:
I thought before that someone uses the pattern can set the role for themselves.
Now, I have add a role in the addroles, it's anonymous user, run this pattern, anyone without login the website can see the toolbar, but the toolbar's empty because the anonymous users don't have the access to see the links in toolbar.

for @csko 4:
I read the user.inc's code, and modify my old pattern.toolbar.inc according your advises in 9ec4582., I think it works through form now.

@csko
Copy link
Contributor

csko commented Nov 22, 2011

@xrfind 1.

You are supposed to write classes which are run by the SimpleTest module. See the examples in tests/ directory, the Patterns7 wiki page in our internal wiki, and the links below.

http://drupal.org/simpletest-tutorial-drupal7
http://drupal.org/node/811254

@ruioaix
Copy link
Contributor

ruioaix commented Nov 24, 2011

@csko
Thanks for your reply!

@msssm
Copy link

msssm commented Nov 24, 2011

@xrfind, I still have some problems.

First I don't understand completely why it looks so complicated to add a link to the toolbar (but I have no deep knowledge of the toolbar module). My questions here are: what exactly is a shortcut_set and why do I need to switch users ?

I tried to follow your instructions but I got this error for pattern switch shortcut set for users (modify):

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /drupal-7.9/batch?id=38&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'uid' cannot be null: INSERT INTO {shortcut_set_users} (uid, set_name) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => shortcut-set-3 ) in shortcut_set_assign_user() (line 445 of /var/www/drupal-7.9/modules/shortcut/shortcut.module).

Anybody has this problem? I think writing the test will help

@ruioaix
Copy link
Contributor

ruioaix commented Nov 25, 2011

Hi,@msssm,
First the toolbar pattern's ability is not add a link, what it does is determining which user can see toolbar and which user cannot.
Second, shortcut_set is a set of some shortcuts, a user can choose a shortcut_set and then he will see this shortcuts_set's shortcuts in the shortcut bar(below the toolbar bar). (actually, he only can see the shortcuts that he has the access to see in the shortcut_set.)

"switch users" can be thought as "a user chooses another shortcut_set".

I run the "switch shortcut set for users(modify)" just now, it's ok.
I am writing the test now, but maybe take some time.

Thanks for your test!

@shakty
Copy link
Owner Author

shakty commented Nov 25, 2011

Ok, thanks, I got it. That error happens when switch shortcut set for users (modify) is run with the name of a non-existing user. Please make sure to raise an error, and stop the process before. This should be done in the validate hook. Write a test for that as well.

There are still some chinese-like names in the yaml files. Could you substitute them all?

@ruioaix
Copy link
Contributor

ruioaix commented Dec 14, 2011

toolbar's test is done.
there is some features in shortcut pattern which can not be test, because the yaml file related to these features has the link's ID, that is diffierent from each case.

the features:

  • edit a link ---- need the link's ID
  • delete a link ---- need the link's ID
  • switch shortcut set for user ---- need a user's name, but the name of the user in the test is diffierent from each case.

How to deal with problems of this kind?

@shakty
Copy link
Owner Author

shakty commented Dec 14, 2011

LINKS:
This is the same problem that Hao had with the menu component.
You should be able to perform those operations based on other types of 'id'.
Instead of the id of the database, use the link name or path for example.
SHORTCUT SET:

I think $this->std_user->name should give you the name of the user for that test.

Or you could write some extra code. Something like the following:

--code--
// Create a user assigned to that role.
$edit = array();
$edit['name'] = 'NAME';
$edit['mail'] = $edit['name'] . '@example.com';
$edit['roles'] = array($rid => $rid);
$edit['pass'] = user_password();
$edit['status'] = 1;

$account = user_save(drupal_anonymous_user(), $edit);

--code--

Then you can login that user and doing the test.

@ruioaix
Copy link
Contributor

ruioaix commented Mar 16, 2012

the ---- in simple test has been deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants