Skip to content

Commit c2ba2a8

Browse files
committed
Add tests for entities using the urilize relative slug handler option
1 parent eb53dfc commit c2ba2a8

File tree

6 files changed

+657
-2
lines changed

6 files changed

+657
-2
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Tests\Sluggable\Fixture\Handler\People;
13+
14+
use Doctrine\Common\Collections\ArrayCollection;
15+
use Doctrine\Common\Collections\Collection;
16+
use Doctrine\DBAL\Types\Types;
17+
use Doctrine\ORM\Mapping as ORM;
18+
use Gedmo\Mapping\Annotation as Gedmo;
19+
use Gedmo\Sluggable\Handler\InversedRelativeSlugHandler;
20+
use Gedmo\Sluggable\Handler\TreeSlugHandler;
21+
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
22+
23+
/**
24+
* @Gedmo\Tree(type="nested")
25+
*
26+
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
27+
*/
28+
#[ORM\Entity(repositoryClass: NestedTreeRepository::class)]
29+
#[Gedmo\Tree(type: 'nested')]
30+
class UrilizedOccupation
31+
{
32+
/**
33+
* @ORM\Id
34+
* @ORM\GeneratedValue
35+
* @ORM\Column(type="integer")
36+
*/
37+
#[ORM\Id]
38+
#[ORM\GeneratedValue]
39+
#[ORM\Column(type: Types::INTEGER)]
40+
private ?int $id = null;
41+
42+
/**
43+
* @ORM\Column(length=64)
44+
*/
45+
#[ORM\Column(length: 64)]
46+
private ?string $title = null;
47+
48+
/**
49+
* @Gedmo\Slug(handlers={
50+
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={
51+
* @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"),
52+
* @Gedmo\SlugHandlerOption(name="separator", value="/")
53+
* }),
54+
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\InversedRelativeSlugHandler", options={
55+
* @Gedmo\SlugHandlerOption(name="relationClass", value="Gedmo\Tests\Sluggable\Fixture\Handler\People\UrilizedPerson"),
56+
* @Gedmo\SlugHandlerOption(name="mappedBy", value="occupation"),
57+
* @Gedmo\SlugHandlerOption(name="inverseSlugField", value="slug")
58+
* })
59+
* }, fields={"title"})
60+
*
61+
* @ORM\Column(length=64, unique=true)
62+
*/
63+
#[Gedmo\Slug(fields: ['title'])]
64+
#[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/'])]
65+
#[Gedmo\SlugHandler(class: InversedRelativeSlugHandler::class, options: ['relationClass' => UrilizedPerson::class, 'mappedBy' => 'occupation', 'inverseSlugField' => 'slug'])]
66+
#[ORM\Column(length: 64, unique: true)]
67+
private ?string $slug = null;
68+
69+
/**
70+
* @Gedmo\TreeParent
71+
*
72+
* @ORM\ManyToOne(targetEntity="UrilizedOccupation")
73+
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
74+
*/
75+
#[ORM\ManyToOne(targetEntity: self::class)]
76+
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
77+
#[Gedmo\TreeParent]
78+
private ?UrilizedOccupation $parent = null;
79+
80+
/**
81+
* @var Collection<int, self>
82+
*/
83+
private Collection $children;
84+
85+
/**
86+
* @Gedmo\TreeLeft
87+
*
88+
* @ORM\Column(type="integer")
89+
*/
90+
#[ORM\Column(type: Types::INTEGER)]
91+
#[Gedmo\TreeLeft]
92+
private ?int $lft = null;
93+
94+
/**
95+
* @Gedmo\TreeRight
96+
*
97+
* @ORM\Column(type="integer")
98+
*/
99+
#[ORM\Column(type: Types::INTEGER)]
100+
#[Gedmo\TreeRight]
101+
private ?int $rgt = null;
102+
103+
/**
104+
* @Gedmo\TreeRoot
105+
*
106+
* @ORM\Column(type="integer")
107+
*/
108+
#[ORM\Column(type: Types::INTEGER)]
109+
#[Gedmo\TreeRoot]
110+
private ?int $root = null;
111+
112+
/**
113+
* @Gedmo\TreeLevel
114+
*
115+
* @ORM\Column(name="lvl", type="integer")
116+
*/
117+
#[ORM\Column(name: 'lvl', type: Types::INTEGER)]
118+
#[Gedmo\TreeLevel]
119+
private ?int $level = null;
120+
121+
public function __construct()
122+
{
123+
$this->children = new ArrayCollection();
124+
}
125+
126+
public function setParent(?self $parent = null): void
127+
{
128+
$this->parent = $parent;
129+
}
130+
131+
/**
132+
* @return Collection<int, self>
133+
*/
134+
public function getChildren(): Collection
135+
{
136+
return $this->children;
137+
}
138+
139+
public function getParent(): ?self
140+
{
141+
return $this->parent;
142+
}
143+
144+
public function getRoot(): ?int
145+
{
146+
return $this->root;
147+
}
148+
149+
public function getLeft(): ?int
150+
{
151+
return $this->lft;
152+
}
153+
154+
public function getRight(): ?int
155+
{
156+
return $this->rgt;
157+
}
158+
159+
public function getLevel(): ?int
160+
{
161+
return $this->level;
162+
}
163+
164+
public function getId(): ?int
165+
{
166+
return $this->id;
167+
}
168+
169+
public function setTitle(?string $title): void
170+
{
171+
$this->title = $title;
172+
}
173+
174+
public function getTitle(): ?string
175+
{
176+
return $this->title;
177+
}
178+
179+
public function getSlug(): ?string
180+
{
181+
return $this->slug;
182+
}
183+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Tests\Sluggable\Fixture\Handler\People;
13+
14+
use Doctrine\DBAL\Types\Types;
15+
use Doctrine\ORM\Mapping as ORM;
16+
use Gedmo\Mapping\Annotation as Gedmo;
17+
use Gedmo\Sluggable\Handler\RelativeSlugHandler;
18+
19+
/**
20+
* @ORM\Entity
21+
*/
22+
#[ORM\Entity]
23+
class UrilizedPerson
24+
{
25+
/**
26+
* @ORM\Id
27+
* @ORM\GeneratedValue
28+
* @ORM\Column(type="integer")
29+
*/
30+
#[ORM\Id]
31+
#[ORM\GeneratedValue]
32+
#[ORM\Column(type: Types::INTEGER)]
33+
private ?int $id = null;
34+
35+
/**
36+
* @ORM\Column(length=64)
37+
*/
38+
#[ORM\Column(length: 64)]
39+
private ?string $name = null;
40+
41+
/**
42+
* @Gedmo\Slug(handlers={
43+
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\RelativeSlugHandler", options={
44+
* @Gedmo\SlugHandlerOption(name="relationField", value="occupation"),
45+
* @Gedmo\SlugHandlerOption(name="relationSlugField", value="slug"),
46+
* @Gedmo\SlugHandlerOption(name="separator", value="/"),
47+
* @Gedmo\SlugHandlerOption(name="urilize", value=true),
48+
* })
49+
* }, separator="-", updatable=true, fields={"name"})
50+
*
51+
* @ORM\Column(name="slug", type="string", length=64, unique=true)
52+
*/
53+
#[Gedmo\Slug(separator: '-', updatable: true, fields: ['name'])]
54+
#[Gedmo\SlugHandler(class: RelativeSlugHandler::class, options: ['relationField' => 'occupation', 'relationSlugField' => 'slug', 'separator' => '/', 'urilize' => true])]
55+
#[ORM\Column(name: 'slug', type: Types::STRING, length: 64, unique: true)]
56+
private ?string $slug = null;
57+
58+
/**
59+
* @ORM\ManyToOne(targetEntity="UrilizedOccupation")
60+
*/
61+
#[ORM\ManyToOne(targetEntity: UrilizedOccupation::class)]
62+
private ?UrilizedOccupation $occupation = null;
63+
64+
public function setOccupation(?UrilizedOccupation $occupation = null): void
65+
{
66+
$this->occupation = $occupation;
67+
}
68+
69+
public function getOccupation(): ?UrilizedOccupation
70+
{
71+
return $this->occupation;
72+
}
73+
74+
public function getId(): ?int
75+
{
76+
return $this->id;
77+
}
78+
79+
public function setName(?string $name): void
80+
{
81+
$this->name = $name;
82+
}
83+
84+
public function getName(): ?string
85+
{
86+
return $this->name;
87+
}
88+
89+
public function getSlug(): ?string
90+
{
91+
return $this->slug;
92+
}
93+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Tests\Sluggable\Fixture\Handler;
13+
14+
use Doctrine\DBAL\Types\Types;
15+
use Doctrine\ORM\Mapping as ORM;
16+
use Gedmo\Mapping\Annotation as Gedmo;
17+
use Gedmo\Sluggable\Handler\InversedRelativeSlugHandler;
18+
use Gedmo\Sluggable\Sluggable;
19+
20+
/**
21+
* @ORM\Entity
22+
*/
23+
#[ORM\Entity]
24+
class UrilizedArticle implements Sluggable
25+
{
26+
/**
27+
* @var int|null
28+
*
29+
* @ORM\Id
30+
* @ORM\GeneratedValue
31+
* @ORM\Column(type="integer")
32+
*/
33+
#[ORM\Id]
34+
#[ORM\GeneratedValue]
35+
#[ORM\Column(type: Types::INTEGER)]
36+
private $id;
37+
38+
/**
39+
* @ORM\Column(name="title", type="string", length=64)
40+
*/
41+
#[ORM\Column(name: 'title', type: Types::STRING, length: 64)]
42+
private ?string $title = null;
43+
44+
/**
45+
* @ORM\Column(name="code", type="string", length=16)
46+
*/
47+
#[ORM\Column(name: 'code', type: Types::STRING, length: 16)]
48+
private ?string $code = null;
49+
50+
/**
51+
* @var string|null
52+
*
53+
* @Gedmo\Slug(handlers={
54+
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\InversedRelativeSlugHandler", options={
55+
* @Gedmo\SlugHandlerOption(name="relationClass", value="Gedmo\Tests\Sluggable\Fixture\Handler\UrilizedArticleRelativeSlug"),
56+
* @Gedmo\SlugHandlerOption(name="mappedBy", value="article"),
57+
* @Gedmo\SlugHandlerOption(name="inverseSlugField", value="slug")
58+
* })
59+
* }, separator="-", updatable=true, fields={"title", "code"})
60+
*
61+
* @ORM\Column(name="slug", type="string", length=64, unique=true)
62+
*/
63+
#[Gedmo\Slug(separator: '-', updatable: true, fields: ['title', 'code'])]
64+
#[Gedmo\SlugHandler(class: InversedRelativeSlugHandler::class, options: ['relationClass' => UrilizedArticleRelativeSlug::class, 'mappedBy' => 'article', 'inverseSlugField' => 'slug'])]
65+
#[ORM\Column(name: 'slug', type: Types::STRING, length: 64, unique: true)]
66+
private $slug;
67+
68+
public function getId(): ?int
69+
{
70+
return $this->id;
71+
}
72+
73+
public function setTitle(?string $title): void
74+
{
75+
$this->title = $title;
76+
}
77+
78+
public function getTitle(): ?string
79+
{
80+
return $this->title;
81+
}
82+
83+
public function setCode(?string $code): void
84+
{
85+
$this->code = $code;
86+
}
87+
88+
public function getCode(): ?string
89+
{
90+
return $this->code;
91+
}
92+
93+
public function getSlug(): ?string
94+
{
95+
return $this->slug;
96+
}
97+
}

0 commit comments

Comments
 (0)