Example #1
0
 public function test_button_components()
 {
     // Test object
     $page = Page::find(1);
     // Check the create method.
     $group = ButtonGroup::create();
     $this->assertInstanceOf(ButtonGroup::class, $group);
     // Shouldn't have anything in it.
     $this->assertCount(0, $group->getButtons());
     // Should return a zero count.
     $this->assertEquals(0, $group->count());
     // Button groups
     $button = Button::create();
     // Check default setting.
     $this->assertNull($button->getAttribute('href'));
     // Adding to the group will increment the button count.
     $group->add($button);
     $this->assertEquals(1, $group->count());
     // Try adding the other way around.
     $button2 = Button::create();
     $button2->addTo($group);
     $this->assertEquals(2, $group->count());
     // Check if the button attributes are assigned correctly.
     $button->parent($page)->link('view');
     $this->assertEquals("View Pages", $button->getLabel());
     $this->assertEquals($page::getIcon(), $button->getIcon());
     $this->assertEquals(cms_url($page::plural()), $button->getAttribute('href'));
 }
Example #2
0
 /**
  * Test basic user authorizations, with models.
  * This should deal directly with the ModelPolicy class.
  */
 public function test_basic_user_auth()
 {
     // User 2 has permission to do a couple things.
     $user = User::find(2);
     $this->assertTrue($user->hasRole(Role::getByName('Administrator')));
     // The models we'll test.
     $page = Page::find(1);
     $this->assertTrue($user->can('view', $page));
     $this->assertFalse($user->can('delete', $page));
     // User model is a managed class. The user doesn't have the manage permission.
     // So, They shouldn't be able to edit a user that doesn't belong to them.
     $testUser = User::find(1);
     $this->assertFalse($user->can('edit', $testUser));
     // But they can edit themselves.
     $this->assertTrue($user->can('edit', $user));
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Page::blueprint()->dropSchema();
 }